?? order.java
字號(hào):
import java.util.*;
/**
* The class Order maintains a list of order items.It contains methods to process vectors of {@link OrderItem} objects.
*
* @author 張維
* @version 1.0.0
* @see OrderItem
* @see Vector
*/
public class Order {
/* Collection of <code>OrderItem</code> objects. */
private Vector items;
/**
* Constructs an empty Order.
*/
public Order( ) {
items = new Vector( );
}
/**
* Adds the specified order item to the order.
*
* @param orderItem the <code>OrderItem</code> object.
*/
public void addItem(OrderItem orderItem) {
items.add(orderItem);
}
/**
* Removes the specified order item from the order.
*
* @param orderItem the <code>OrderItem</code> object.
*/
public void removeItem(OrderItem orderItem) {
items.remove(orderItem);
}
/**
* Returns an iterator over the instances in the items.
*
* @return an <code>Iterator</code> object.
*/
public Iterator getItemsIterator( ) {
return items.iterator( );
}
/**
* Returns a reference to the OrderItem instance with the specified product.
* Returns null if there are no items in the order with the specified product.
*
* @param product a <code>Product</code> object.
* @return the <code>OrderItem</code> object with the specified <code>product</code>.
*/
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 instances in the vector items.
*
* @return the number of <code>OrderItem</code> objects in the vector items.
*/
public int getNumberOfItems( ) {
return items.size( );
}
/**
* Returns the total cost of the order.
*
* @return the total cost of the order.
*/
public double getTotalCost( ) {
double totalCost = 0.0D;
for (Iterator i = getItemsIterator( );i.hasNext( );) {
OrderItem orderItem = (OrderItem)i.next( );
totalCost = totalCost + orderItem.getValue( );
}
return totalCost;
}
/**
* Returns an array of the OrderItem objects (all the items in the current order),
* which is used by GourmetCoffeeGUI to populate the order JList.
*
* @return an array of all the items in the current order
*/
public OrderItem[ ] getItems( ) {
OrderItem aorderitem[ ] = new OrderItem[getNumberOfItems( )];
int i = 0;
for(Iterator iterator = getItemsIterator( ); iterator.hasNext( );)
aorderitem[i++] = (OrderItem)iterator.next();
return aorderitem;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -