📄 exercise 4.sales.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -