-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDinnerMenu.java
More file actions
51 lines (42 loc) · 1.44 KB
/
DinnerMenu.java
File metadata and controls
51 lines (42 loc) · 1.44 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
44
45
46
47
48
49
50
51
package IteratorPattern.MenuExample;
public class DinnerMenu {
static final int MAX_ITEMS = 6;
int numberOfItems = 0;
MenuItem[] menuItems;
public DinnerMenu() {
menuItems = new MenuItem[MAX_ITEMS];
addItem("Vegetarian BLT",
"(Fakin') Bacon with lettuce & tomato on whole wheat",
true,
2.99);
addItem("BLT",
"Bacon, Lettuce & Tomato on whole wheat",
true,
2.99);
addItem("Soup of the day",
"Soup of the day, with a side of potato salad",
false,
3.29);
addItem("Hotdog",
"A hot dog, with sauteed onions, relish, mustard",
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.err.println("Sorry, menu is full!");
} else {
menuItems[numberOfItems] = menuItem;
numberOfItems++;
}
}
// After setting up iterator this isn't needed anymore
// It exposes the internal structure
// public MenuItem[] getMenuItems() {
// return menuItems;
// }
public Iterator createIterator() {
return new DinnerMenuIterator(menuItems);
}
}