abstract class Goods
{
protected double unitPrice;
protected int account;
public double totalPrice()
{
return unitPrice * account;
}
}
class Apple extends Goods
{
private String name;
public Apple(String name, double unitPrice, int account)
{
this.name = name;
this.unitPrice = unitPrice;
this.account = account;
}
public void show()
{
System.out.printf("%s,%.2f元/斤,%d斤,共%.2f元", name, unitPrice, account, totalPrice());
}
}
interface VipPrice
{
double DISCOUNT = 0.8;
double reducedPrice();
}
class Clothing extends Goods implements VipPrice
{
private String style;
public Clothing(String style, double unitPrice, int account)
{
this.style = style;
this.unitPrice = unitPrice;
this.account = account;
}
@Override
public double reducedPrice()
{
return this.unitPrice *= DISCOUNT;
}
public void show()
{
System.out.printf("单价:%.2f 元,数量:%d 件,样式:%s,VIP价格信息:%.2f 元", unitPrice, account, style, reducedPrice());
}
}
public class Main
{
public static void main(String[] args)
{
Apple apple = new Apple("红富士", 10, 2);
apple.show();
System.out.println();
Clothing clothing = new Clothing("女装", 300, 2);
clothing.show();
}
}