exercise 4.sales.java

来自「CMU SSD3 课程完整答案(除EXAM)」· Java 代码 · 共 55 行

JAVA
55
字号
import java.util.*;

/**
 * The class maintains a list of the orders that have been completed. This
 * class implements the interface Iterable<Order> to being able to iterate
 * through the orders using the for-each loop.
 * 
 * @author Neil
 * @version 1.1.0
 * @see Order
 */
public class Sales implements Iterable<Order> {
	
	private ArrayList<Order> orders;

	/**
	 * Creates the collection orders, which is initially empty.
	 */
	public Sales() {
		
		orders = new ArrayList<Order>();		
	}

	/**
	 * Adds the specified order to the collection orders.
	 * 
	 * @param order
	 *            the order to be added.
	 */
	public void addOrder(Order order) {
		
		orders.add(order);		
	}

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

	/**
	 * Returns the number of instances in the collection orders.
	 * 
	 * @return Returns the number of instances in the collection orders.
	 */
	public int getNumberOfOrders() {
		
		return orders.size();
	}
}

⌨️ 快捷键说明

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