题目:现有父类Goods,在此基础上派生出子类Clothing,子类定义了自己的属性String类型的类别(style),
有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,
请实现Clothing类的编写
-------------------------------------------------------*/
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account) {
this.unitPrice=unitPrice ;
this.account=account ;
}
double totalPrice() {//计算总价格
return unitPrice * account;
}
void show() {
System.out.println("单价是" + unitPrice);
System.out.println("购买数量为" + account);
System.out.println("购买商品的总金额是" + this.totalPrice());
}
}
class Clothing extends Goods {
/**********Program**********/
/********** End **********/
}
public class Prog1{
public static void main(String[] args){
}
}
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account){
this.unitPrice = unitPrice;
this.account = account;
}
double totalPrice(){//计算总价
return unitPrice*account;
}
void show(){
System.out.println("单价:"+unitPrice);
System.out.println("购买数量:"+account);
System.out.println("购买商品的总金额:"+this.totalPrice());
}
}
class Clothing extends Goods{
String style;//样式
Clothing(String style, double unitPrice, double account) {
super(unitPrice, account);
this.style = style;
}
void show(){
System.out.println("衣服单价:"+unitPrice);
System.out.println("衣服数量:"+account);
System.out.println("衣服总金额:"+this.totalPrice());
}
void showClothing(){
System.out.println("衣服样式:"+style);
this.show();
}
}
public class Prog1{
public static void main(String[] args) {
Clothing clothing = new Clothing("蓝色风衣",100,2);
clothing.showClothing();
}
}