JAVA练习题

来源:百度知道 编辑:UC知道 时间:2024/05/24 03:33:26
练习题:
1、昨天我去香山买东西,买了这些商品:
(1)编码:10931
商品名:实荣单晶冰糖
单价:1.9
数量:1
金额:1.9
(2)编码:15935
商品名:加碘精制盐
单价:1.3
数量:2
金额:2.6
(3)编码:10995
商品名:火鸟色拉油
单价:64.8
数量:1
金额:64.8

要求定义一个商品类Item,构造以上实体对象,要求定义方法,求出每种商品的金额,以及商品总价。

这是一个最基本的Domain对象,不知道你那里不理解

它对应数据库的一条记录。

public class Item {
private Integer id; // 编码

private String name;// 名称

private Integer price;// 单价

private Integer amount;// 数量

private Integer total;// 合计金额

public Integer getAmount() {
return amount;
}

public void setAmount(Integer amount) {
this.amount = amount;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Integer getPrice() {
return price;
}

public void setPrice(Integer price) {
this.price = price;
}

public Integer getTotal() {
return total;
}

public void setTotal(Integer total) {