-
Notifications
You must be signed in to change notification settings - Fork 687
Expand file tree
/
Copy pathMenu.java
More file actions
88 lines (72 loc) · 2.31 KB
/
Menu.java
File metadata and controls
88 lines (72 loc) · 2.31 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package org.launchcode;
import java.util.ArrayList;
import java.util.Date;
public class Menu {
@Override
public String toString() {
/* return "Menu{" +
"lastUpdated=" + lastUpdated +
", items=" + items +
'}';*/
return "Menu (Last Updated: " + lastUpdated + ")\n items=" + items;
}
private Date lastUpdated;
private ArrayList<MenuItem> items;
public Menu(Date d, ArrayList<MenuItem> i) {
this.lastUpdated = d;
this.items = i;
}
// Add item to menu and update the lastUpdated date
public void addItem(MenuItem item) {
this.items.add(item);
updateLastUpdated();
}
// // Remove item from menu and update the lastUpdated date
public void removeItem(MenuItem item) {
this.items.remove(item);
updateLastUpdated();
}
// Print a single menu item
public void printMenuItem(MenuItem item) {
System.out.println("Description: " + item.getDescription());
System.out.println("Category: " + item.getCategory());
System.out.println("Price: $" + item.getPrice());
System.out.println("New Item: " + (item.isNew() ? "Yes" : "No"));
System.out.println();
}
// Print the entire menu
public void printMenu() {
System.out.println("Menu (Last Updated: " + lastUpdated + ")");
for (MenuItem item : items) {
printMenuItem(item);
}
//System.out.println(this);
}
public void printItemsWithDescription(String startOfDescription) {
boolean found = false;
for (MenuItem item : items) {
if (item.getDescription().toLowerCase().startsWith(startOfDescription)) {
printMenuItem(item);
found = true;
}
}
if (!found) {
System.out.println("No items matched your description.");
}
}
private void updateLastUpdated() {
this.lastUpdated = new Date();
}
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
public void setItems(ArrayList<MenuItem> items) {
this.items = items;
}
public Date getLastUpdated() {
return lastUpdated;
}
public ArrayList<MenuItem> getItems() {
return items;
}
}