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()));
}
}