public class God
{
public int amount;
public String name;
public int oneprice;
public void God(String name,int amount,int price)
{ this.name=name;
this.amount=amount;
this.oneprice=price;}
public int AllPrice()
{
return amount*oneprice;}
}
public CutGod extends God
{
public float cutRate=0.88;
public CutGod(String name,int amount,int price,float cutRate){
super(name,amount,price);
this.cutRate=cutRate;
}
public float AllPrice()
{
return amount*oneprice*cutRate;
}}
public class Main {
public static void main(String[] args)
{
God book=new God("book",10,30); //名为书的货物,单价30,共有10本。
cutGod computer =new cutGod("computer",100,2000,0.88);//名为电脑的货物,单价2000,共有100台。打8.8折
System.out.println("所有书的价格是:"+book.AllPrice());
System.out.println("所有电脑的价格是:"+computer.AllPrice());
}}
//三个类,分别建成一个类文件,放在同一个包中,
取消
评论