资源下载
源码 http://chenjinsui.com/oop_homework.zip
UML图
当然,不是我画的,文档里给的。
Product 类
注意两点就好。第一个是equals
方法,只需要比较code
即可,不需要比较description
和price
。第二个就是toString
方法要和测试文档里的格式相符合。
equals
方法
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Product product = (Product) o;
return code.equals(product.code);
}
toString
方法
@Override
public String toString() {
return code + "_" + description + "_" + price;
}
Coffee 类、CoffeeBrewer类
没什么要注意的,构造器参数顺序和测试文档的一致就可以。
toString
方法也要按照所给的格式来。
OrderItem 类
getValue
方法
public double getValue(){
return product.getPrice() * quantity;
}