-
Notifications
You must be signed in to change notification settings - Fork 685
Expand file tree
/
Copy pathMenu.java
More file actions
43 lines (39 loc) · 1.36 KB
/
Menu.java
File metadata and controls
43 lines (39 loc) · 1.36 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 org.launchcode;
import java.util.ArrayList;
import java.util.Date;
public class Menu {
private ArrayList<MenuItem> menuItems = new ArrayList<>();
public ArrayList<MenuItem> getMenuItems() {
return menuItems;
}
public String toString() {
StringBuilder appetizers = new StringBuilder();
for (MenuItem item : menuItems) {
if (item.getCategory().equals("appetizer")) {
appetizers.append("\n" + item.toString() + "\n");
}
}
StringBuilder mainCourses = new StringBuilder();
for (MenuItem item : menuItems) {
if (item.getCategory().equals("main course")) {
mainCourses.append("\n" + item.toString() + "\n");
}
}
StringBuilder desserts = new StringBuilder();
for (MenuItem item : menuItems) {
if (item.getCategory().equals("dessert")) {
desserts.append("\n" + item.toString() + "\n");
}
}
return "\nTONY'S PIZZA MENU\n" +
"APPETIZERS" + appetizers.toString() + "\n" +
"MAIN COURSES" + mainCourses.toString() + "\n" +
"DESSERTS" + desserts.toString() + "\n";
}
void removeItem(MenuItem item) {
menuItems.remove(item);
}
void addItem(MenuItem newItem) {
menuItems.add(newItem);
}
}