sales.java

来自「ssd2 exercise4 的题目和答案」· Java 代码 · 共 54 行

JAVA
54
字号
import java.util.*;

/**
 * Maintains a list of the orders that have been completed. Contains a
 * collection of {@link Order} objects.
 *
 * @author Libo Du
 * @version  1.0.0
 * @see Order
 */
public class Sales implements Iterable<Order>{

	/* Collection of <code>Order</code> objects.*/
	private ArrayList<Order> orders;
	
	/**
     * Constructs an collection <code>orders</code>, which is initially empty. 
     */
	public Sales(){
        
    	orders = new ArrayList<Order>();
    }

	/**
     * Add the specified {@link Order} to the collection <code>orders</code>. 
     * 
     * @param order  the specified {@link Order} object.
     */
    public void addOrder(Order order){
        
    	orders.add(order);
    }

    /**
     * Returns an iterator over the instances in the collection <code>orders</code>.
     * 
     * @return  an {@link Iterator} of {@link Order}
     */
    public Iterator<Order> iterator(){
        
    	return orders.iterator();
    }

    /**
     * Returns the number of instances in the collection <code>orders</code>.
     *
     * @return the number of {@link Order} objects in this sale.
     */
    public int getNumberOfOrders(){
        
    	return orders.size();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?