-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDinerMenu.java
More file actions
43 lines (36 loc) · 1.08 KB
/
DinerMenu.java
File metadata and controls
43 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package iterator;
import iterator.impl.DinerMenuIterator;
/**
* Created by http://teachcourse.cn on 2018/03/22.
*/
public class DinerMenu {
static final int MAX_ITEMS = 6;
int numberOfItems = 0;
MenuItem[] menuItems;
public DinerMenu() {
menuItems = new MenuItem[MAX_ITEMS];
addItem("Vegetarian BLT",
"(Fakin') Bacon with lettuce & tomato on whole wheat", true,
2.99);
addItem("BLT", "Bacon with lettuce & tomato on whole wheat", false,
2.99);
addItem("Soup of the day",
"Soup of the day,with a side of potato salad", false, 3.99);
addItem("Hotdog",
"A hot dog,with saurkraut,relish,onions,topped with cheese",
false, 3.05);
}
public void addItem(String name, String description, boolean vegetarian,
double price) {
MenuItem menuItem = new MenuItem(name, description, vegetarian, price);
if (numberOfItems >= MAX_ITEMS)
System.out.println("Sorry,menu is full!! Can't add item to menu");
else {
menuItems[numberOfItems] = menuItem;
numberOfItems++;
}
}
public Iterator createIterator() {
return new DinerMenuIterator(menuItems);
}
}