-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
268 lines (252 loc) · 7.84 KB
/
Copy pathOrder.java
File metadata and controls
268 lines (252 loc) · 7.84 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import java.util.ArrayList;
import java.util.*;
public class Order {
public String[] foodList = {"CHICKEN BIRYANI", "KF AND C", "MAC DONALDS", "PASTA", "SANDWICH", "GYOZA", "RAMEN", "SUSHI", "SOBA", "DUMPLINGS", "COKE", "PEPSI", "SPRITE", "ROOT BEER", "MILK", "TEA", "MILK TEA", "BOBA TEA", "CURRY", "FRIED RICE", "FRIED NOODLES", "CARROT CAKE", "PIZZA", "FRUIT CUP", "SALAD"};
private ArrayList<String> food = new ArrayList<String>();
private boolean isPriority;
private boolean isNormal;
private boolean isSaver;
private int time;
private House house;
public Order() // Order is randomized
{
int listNum = foodList.length;
int randomAmt = (int)(Math.random() * 3) + 1; // Sets a random amount of food that will be inserted in Order
for(int i = 0 ; i < randomAmt ; i++) // Iterates to add the food into the food variable
{
this.food.add((foodList[(int)(Math.random() * listNum)]));
}
int random = (int)(Math.random() * 3); // Fairly randomizing priority chances
if(random == 0) // Be prioritised
{
this.isPriority = true;
this.isNormal = false;
this.isSaver = false;
this.time = 40;
}
if(random == 1) // Be normal
{
this.isPriority = false;
this.isNormal = true;
this.isSaver = false;
this.time = 90;
}
if(random == 2) // Be saver
{
this.isPriority = false;
this.isNormal = false;
this.isSaver = true;
this.time = 200;
}
}
public Order(House house, int priority, int normal, int saver) // Lowers or increases chances of priority orders
{
this.house = house;
int listNum = foodList.length;
int randomAmt = (int)(Math.random() * 2) + 1; // Randomises amount of food in order
for(int i = 0 ; i < randomAmt ; i++) // Iterates and adds food into food variable
{
this.food.add(foodList[(int)(Math.random() * listNum)]);
}
int total = priority + normal + saver;
Random ran = new Random();
int random = ran.nextInt(0, total);
if(random < priority) // If the random quantity is at priority level, its prioritised order
{
this.isPriority = true;
this.isNormal = false;
this.isSaver = false;
this.time = 30;
}
else if(random < priority + normal) // If the random quantity is at normal level, its normal order
{
this.isNormal = true;
this.isPriority = false;
this.isSaver = false;
this.time = 50;
}
else // If the random quantity is at saver level, its saver order
{
this.isSaver = true;
this.isPriority = false;
this.isNormal = false;
this.time = 200;
}
}
public Order(ArrayList<String> food, int typeOfDelivery, House house) // Order is customized!!
{
this.food = food;
if(typeOfDelivery == 1) // Set to prioritised
{
this.isPriority = true;
this.time = 30;
this.house = house;
}
else if(typeOfDelivery == 2) // Set to normal
{
this.isNormal = true;
this.time = 50;
this.house = house;
}
else if(typeOfDelivery == 3) // set to saver
{
this.isSaver = true;
this.time = 200;
this.house = house;
}
}
public Order(String food, String typeOfDelivery, House house) // Order is customized!!
{
this.food.add(food);
if(typeOfDelivery.equalsIgnoreCase("priority")) // Set to priority
{
this.isPriority = true;
this.isNormal = false;
this.isSaver= false;
this.time = 30;
this.house = house;
}
else if(typeOfDelivery.equalsIgnoreCase("normal")) // Set to normal
{
this.isNormal = true;
this.isSaver = false;
this.isPriority = false;
this.time = 50;
this.house = house;
}
else if(typeOfDelivery.equalsIgnoreCase("saver")) // Set to saver
{
this.isSaver = true;
this.isNormal = false;
this.isPriority = false;
this.time = 200;
this.house = house;
}
else // If it's invalid input
{
System.out.println("You can't input that");
}
}
public void setFood(ArrayList<String> newFood) // Sets the food to the new food arraylist
{
this.food = newFood;
}
public void setTime(int newTime) // Sets up time to the new time
{
this.time = newTime;
}
public void timeTick() // Time goes down by one second and also makes this true for the house variable
{
if(house!=null)
{
this.time--;
house.timeTick();
}
}
public void setPriority() // Set to priority
{
this.isPriority = true;
this.isNormal = false;
this.isSaver = false;
}
public void setNormal() // Set to normal
{
this.isPriority = false;
this.isNormal = true;
this.isSaver = false;
}
public void setSaver() // Set to saver
{
this.isPriority = false;
this.isNormal = false;
this.isSaver = true;
}
public String getPriority() // Returns the priority of order
{
if(isPriority) // If its priority, return priority
{
return "Priority";
}
else if(isNormal) // If its normal, return normal
{
return "Normal";
}
else if(isSaver) // If its saver, return saver
{
return "Saver";
}
else // If it's somehow nothing else
{
return "DNE";
}
}
public int getTime() // Returns time
{
return time;
}
public String getFood() // Returns the food like how it's listed
{
String message = "";
if(food.size() == 1)
{
message += food.get(0);
return message;
}
else if(food.size() > 1)
{
for(int i = 0 ; i < food.size() - 1; i++) // Iterates the food variable and adds it to message in the right order
{
message += food.get(i) + ", ";
}
message += food.get(food.size() - 1); // Making sure message doesn't add with a comma
return message;
}
else
{
return message;
}
}
public House getHouse() // Return the house information
{
return this.house;
}
@Override
public String toString() // To be displayed in other methods and classes
{
if(isPriority) // If its priority
{
return "Order: " + getFood() + "\nPriority: Prioritised Delivery Time Left: " + time;
}
if(isNormal) // If its normal
{
return "Order: " + getFood() + "\nPriority: Normal Delivery Time Left: " + time;
}
if(isSaver) // If its saver
{
return "Order: " + getFood() + "\nPriority: Saver Delivery Time Left: " + time;
}
else // If its none of those above
{
return "DNE";
}
}
public String toString1() // To be displayed in other methods and classes
{
if(isPriority) // If its priority
{
return "Order: " + getFood();
}
if(isNormal) // If its normal
{
return "Order: " + getFood();
}
if(isSaver) // If its saver
{
return "Order: " + getFood();
}
else // If its none of those above
{
return "DNE";
}
}
}