精通JAVA的进,我急用

来源:百度知道 编辑:UC知道 时间:2024/06/21 22:44:00
练习题:(JAVA语言编译,ECLIPSE编译器【要求代码都是面向对象部分的内容编译】)
1、昨天我去香山买东西,买了这些商品:
(1)编码:10931
商品名:实荣单晶冰糖
单价:1.9
数量:1
金额:1.9
(2)编码:15935
商品名:加碘精制盐
单价:1.3
数量:2
金额:2.6
(3)编码:10995
商品名:火鸟色拉油
单价:64.8
数量:1
金额:64.8

要求定义一个商品类Item,构造以上实体对象,要求定义方法,求出每种商品的金额,以及商品总价。
在控制台上输出(和数据库没关系的)

没有说明白,是从数据库里面查询出来然后在IE里面列表形式
还是编辑几个类在控制台上输出出来

class Item
{
String ID;
String name;
double price;
public Item(String ID,String name,double price)
{
this.ID = ID;
this.name = name;
this.price = price;
}
public String getID()
{
return ID;
}
public String getName()
{
return name;
}
public double getPrice()
{
return price;
}
}
class Customer
{
double totalMoney = 0;
public void buy(Item goods,int amount)
{
System.out.println("购买: "+ goods.getName()+" 数量: "+amount+" 金额: "+(goods.getPrice()*amount));
totalMoney += (goods.getPrice() * amount);
}
public double getTotal()
{
return totalMoney;
}
public static void main(String [] args)
{
Item sweet = new Item("10931","实荣单晶冰糖",1.9);
Item salt = ne