📄 order.java
字号:
import java.util.*;
import java.text.*;
/**
* Maintains a collection of {@link OrderItem}
* assigned to a buyer.
*
* @author XuWeiyue
* @version 1.0.0
* @see OrderItem
*/
public class Order
{
/* Catalog items assigned to a buyer.*/
private Vector items;
/**
* Sets the collection of {@link OrderItem} to empty.
*/
public Order()
{
items = new Vector();
}
/**
* Adds a {@link CatalogItem} object to this collection and
* sets the {@link CatalogItem} object as not available.
*
* @param item the {@link CatalogItem} object.
*/
public void addItem(OrderItem orderItem)
{
items.add(orderItem);
}
/**
* Removes a {@link CatalogItem} object from this collection
* and sets the {@link CatalogItem} object as available.
*
* @param item the {@link CatalogItem} object.
*/
public void removeItem(OrderItem orderItem)
{
items.removeElement(orderItem);
}
/**
* Returns an iterator over the borrowed items in this
* collection.
*
* return an {@link Iterator}
*/
public Iterator getItemsIterator()
{
return items.iterator();
}
/**
* Returns the {@link CatalogItem} object with the specified
* <code>code</code>.
*
* @param code the code of an item.
* @return The {@link CatalogItem} object with the specifed
* code. Returns <code>null</code> if the object with
* the code is not found.
*/
public OrderItem getItem(Product product)
{
for (Iterator i = getItemsIterator(); i.hasNext();)
{
OrderItem orderItem = (OrderItem) i.next();
if (orderItem.getProduct().equals(product))
{
return orderItem;
}
}
return null;
}
/**
* Returns the number of borrowed items.
*
* @return the number of borrowed items.
*/
public int getNumberOfItems()
{
return items.size();
}
public double getTotalCost()
{
double d = 0.0D;
for(Iterator i = getItemsIterator(); i.hasNext();)
{
d += ((OrderItem)iterator.next()).getValue();
}
return d;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -