请问这道JAVA代码怎么敲出来,初学小白求指教

class Good { String name; int price; int
请问这道JAVA代码怎么敲出来,初学小白求指教
class Good {
String name;
int price;
int count;

public void printInfo() {
System.out.println(name + "芦梁\t" + price + "\t" + count + "\t" + count*price);
}

}

class TShirt extends Good {
public TShirt(int count) {
this.name = "T恤";
this.price = 245;
this.count = count;
}
}

class TennisShoe extends Good {
public TennisShoe(int count) {
this.name = "网球鞋";
this.price = 570;
this.count = count;
}
}

class TennisRacket extends 亩哗宴Good {
public TennisRacket(int count) {
this.name = "网球拍";
this.price = 320;
this.count = count;
}
}

class Person {
String name;
double discount = 0.8;
double total = 0;
Good g;
int 迅银score = 0;

public Person(String name) {
this.name = name;
}

public void buy(Good g) {
total += g.count * g.price * discount;
}

}

public class TestDemo {

public static void main(String[] args) {

Good a = new TShirt(2);
Good b = new TennisShoe(1);
Good c = new TennisRacket(1);
Person ZS = new Person("张三");

System.out.println("*********消费单**********");
System.out.println("购买商品" + "\t" + "单价(元)" + "\t" + "数量" + "\t" + "金额(元)");
a.printInfo();
b.printInfo();
c.printInfo();

ZS.buy(a);
ZS.buy(b);
ZS.buy(c);
System.out.println();
System.out.println("折扣:" + ZS.discount);
System.out.println("金额总计:" + ZS.total);

}

}

你们这道题的意思应该是考察类的继承和多态吧。基本思路写出来了,打印也差不多跟你的一样,给多少钱找零多少以及积分多少自己算就行,总金额就是变量total。


用手.............................

← 上一篇:请问原木色地板、淡黄色墙配什么 下一篇:历史与文学区别是什么呢? →