orderimp.java
来自「著名的uncle Bob的Agile software development的」· Java 代码 · 共 45 行
JAVA
45 行
import java.util.Vector;
public class OrderImp implements Order
{
private Vector itsItems = new Vector();
private String itsCustomerId;
public String getCustomerId()
{
return itsCustomerId;
}
public OrderImp(String cusid)
{
itsCustomerId = cusid;
}
public void addItem(Product p, int qty)
{
Item item = new Item(p,qty);
itsItems.add(item);
}
public int total()
{
try
{
int total = 0;
for (int i = 0; i < itsItems.size(); i++)
{
Item item = (Item) itsItems.elementAt(i);
Product p = item.getProduct();
int qty = item.getQuantity();
total += p.getPrice() * qty;
}
return total;
}
catch (Exception e)
{
throw new Error(e.toString());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?