已有101人关注
拓展训练二,显示无错误,无法运行
发表在Java图书答疑 2018-11-06 《零基础学Java》第7章 面向对象核心技术 156页-156页
是否精华
版块置顶:


class fruit {

String name;

double price;

double weight;


public String getName() {

return name;

}


public void setName(String name) {

this.name = name;

}


public double getPrice() {

return price;

}


public void setPrice(double price) {

this.price = price;

}


public double getWeight() {

return weight;

}


public void setWeight(double weight) {

this.weight = weight;

}

}


public class Fruit extends fruit {

private double packagesfee;


public double getPackagesfee() {

return packagesfee;

}


public void setPackagesfee(double packagesfee) {

this.packagesfee = packagesfee;

}


public static void main(String[] args) {

fruit a = new fruit();

a.setName("苹果");

a.setPrice(1.98);

a.setWeight(5.0);

Fruit b = new Fruit();

b.setName("精装苹果");

b.setPrice(2.98);

b.setWeight(5.0);

b.setPackagesfee(((double) b.getPackagesfee() - (double) a.getPrice()));

System.out.println("水果名称\t水果价格(元/千克)\t水果重量(千克)\t包装费(元/千克)\t总价");

System.out.println(""

+ "------------------------------------------------------------------------------------------");

System.out.println(a.getName() + "\t" + a.getPrice() + "\t" + a.getWeight() + "\t" + "0.0\t"

+ a.getPrice() * a.getWeight());

System.out.println(b.getName() + "\t" + b.getPrice() + "\t" + b.getWeight() + "\t" + b.getPackagesfee() + "\t"

+ b.getPrice() * b.getWeight());

System.out.println(

"--------------------------------------------------------------------------------------------");

System.out.println("差价\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"

+ (b.getPrice() * b.getWeight() - a.getPrice() * a.getWeight()));

}

}

4.png


分享到:
精彩评论 1
根号申
学分:4736 LV12
TA的每日心情
2021-07-16 23:48:46
2018-11-06
沙发

类名大小写错了

首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照