-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderingSystem.java
More file actions
132 lines (102 loc) · 2.9 KB
/
OrderingSystem.java
File metadata and controls
132 lines (102 loc) · 2.9 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package assignment6;
import java.util.Iterator;
/**
* The ordering system class that the driver will manage.
*
* @author Rían Adamian
* @since 13/11/2018
*/
public class OrderingSystem {
public Order current;
public Menu menu;
public OrderingSystem(Menu menu) {
this.menu = menu;
this.current = null;
}
/**
* This method creates a new order for the system to handle. If there is already one then it must be finalized.
*/
public void newOrder() {
if (current != null) {
System.out.println("There is an existing order yet to be completed!");
} else {
current = new Order();
System.out.println("A new order has been created.");
}
}
/**
* This method lists all items on the menu, followed by their price.
*/
public void listAll() {
System.out.println(menu.listMenu());
}
/**
* This method allows the customer to add an item to the current order.
*
* @param name The name of the item requested.
*/
public void addToOrder(String name) {
if (current == null) {
System.out.println("You must begin a new order!");
} else {
Iterator<Item> iterator = menu.menu.iterator();
whileLoop:
while (iterator.hasNext() == true) {
Item i = iterator.next();
if (i.getName() == name) {
if (i.getClass() == Drink.class) {
Drink d = (Drink) i;
if (d.alc = true) {
System.out.println("You must be 18 years old to buy this.");
}
}
current.add(i);
System.out.println("Your order has been updated: " + current.toString());
break whileLoop;
}
}
}
}
/**
*
* This method allows the customer to explicitly access the full meal combo.
* Any valid item requested that is on the menu is added to the order.
*
* @param appetizer The desired appetizer of the combo
* @param main The desired main course of the combo
* @param dessert The desired dessert of the combo
*/
public void createFullMeal(String appetizer, String main, String dessert) {
Item a = null;
Item m = null;
Item d = null;
Iterator<Item> iterator = menu.menu.iterator();
while (iterator.hasNext() == true) {
Item i = iterator.next();
if (i.getName() == appetizer && i.getType() == "Appetizer") {
a = i;
}
if (i.getName() == main && i.getType() == "Main") {
m = i;
}
if (i.getName() == dessert && i.getType() == "Dessert") {
d = i;
}
}
if ((a == null || m == null) || d == null) {
System.out.println("Invalid order.");
} else {
current.add(a);
current.add(m);
current.add(new DiscountItem(d, 0.5));
}
}
/**
* This method relays the total cost of the customer's order and demands that they pay.
* Then it closes the order the System is handling so a new one can be created.
*/
public void finalizeOrder() {
System.out.println("The cost of your order is: " + current.getPrice() + "\nPlease pay now.");
current = null;
}
}