-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCafeMenu.java
More file actions
28 lines (21 loc) · 948 Bytes
/
CafeMenu.java
File metadata and controls
28 lines (21 loc) · 948 Bytes
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
package IteratorPattern.MenuJavaUtilsExample;
import java.util.HashMap;
import java.util.Iterator;
public class CafeMenu implements Menu {
HashMap<String, MenuItem> menuItems = new HashMap<String, MenuItem>();
public CafeMenu() {
addItem("Veggie Burger and Air Fries",
"Veggie burger on a whole wheat bun, lettuce, tomato, and fries",
true,
3.99);
addItem("Soup of the Day", "A cup of the soup of the day, with a side salad", false, 3.69);
addItem("Burrito", "A large burrito with beans, cheese, and salsa", true, 4.29);
}
public void addItem(String name, String description, boolean vegetarian, double price) {
MenuItem menuItem = new MenuItem(name, description, vegetarian, price);
menuItems.put(menuItem.getName(), menuItem);
}
public Iterator<MenuItem> createIterator() {
return menuItems.values().iterator();
}
}