-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurantM.java
More file actions
652 lines (641 loc) · 41.5 KB
/
RestaurantM.java
File metadata and controls
652 lines (641 loc) · 41.5 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
import java.util.*;
import java.io.*;
public class RestaurantM {
public static void main(String[] args) throws Exception {
File file = new File("D:\\Javabin\\Restaurant.txt");
Scanner fileS = new Scanner(file);
Scanner fileScanner = new Scanner(file);
Scanner inputSearchMenu = new Scanner(System.in);
try {
file.delete();
file.createNewFile();
Restaurant dRestaurant;
Waiter dWaiter;
Customer dCustomer;
RestaurantStack rStack = new RestaurantStack();
WaiterStack WaiterStack = new WaiterStack();
CustomerStack customerStack = new CustomerStack();
RestaurantLL list = new RestaurantLL();
WaiterLL calist = new WaiterLL();
CustomerLL culist = new CustomerLL();
Menu delete = new Menu();
MenuLL menulist = new MenuLL();
MenuStack menuStack = new MenuStack();
int choice, choice1, choice2, choice3;
Scanner input = new Scanner(System.in);
do {
System.out
.print("________________Welcome to Restaurant Management System________________\n\n[1] Waiter\n[2] Order \n[3] Menu\n[4] Customer\n[5] Exit\nEnter choice: ");
choice = input.nextInt();
if (choice == 4) {
do {
System.out.print(
"=====Customer=====\n\n[1] ShowList\n[2] Delete\n[3] Search\n[4] Sort\n[5] Clear\n[6] ADD\n[7] Undo\n[8] Read From File\n[9] Save In File\n[10] Exit\nEnter choice: ");
choice1 = input.nextInt();
if (choice1 == 1) {
culist.showList();
} else if (choice1 == 2) {
dCustomer = culist.deleteCustomer();
customerStack.push(dCustomer);
list.deleteCustomer(dCustomer.getCustomerID());
} else if (choice1 == 3) {
System.out.print("Enter name to search: ");
String name = input.next();
while (name.length() == 1) {
System.out.println("Name Invalid\nPlease Type Again: ");
name = input.next();
}
Customer found = culist.searchName(name);
if (found == null)
System.out.println("Not in the list.");
else {
System.out.println(found.getName() + " " + found.getAge());
int searchMenu;
do {
System.out.print(
"MENU SEARCH\n====\n[1] NEXT\n[2] PREVIOUS\n[3] BACK\nEnter your choice: ");
searchMenu = inputSearchMenu.nextInt();
if (searchMenu == 1) {
found = culist.goToNext(found);
System.out.println(found.getName() + " " + found.getAge());
} else if (searchMenu == 2) {
found = culist.goToPrevious(found);
System.out.println(found.getName() + " " + found.getAge());
}
if (searchMenu == 3) {
}
} while (searchMenu != 3);
}
} else if (choice1 == 4) {
culist.sortList();
} else if (choice1 == 5) {
culist.clear();
} else if (choice1 == 6) {
System.out.print("\nName: ");
String name = input.next();
System.out.print("\nAge: ");
int age = input.nextInt();
System.out.print("\nId: ");
int id = input.nextInt();
while (culist.checkIDExsitance(id)) {
System.out.print("\nId Already Exist\nInput Again: ");
id = input.nextInt();
}
culist.addCustomerStart(age, name, id);
} else if (choice1 == 7) {
Customer a = customerStack.pop();
if (a == null)
System.out.println("Nothing to undo.");
else
culist.addCustomerStart(a.getAge(), a.getName(), a.getCustomerID());
} else if (choice1 == 8) {
culist = culist.ReadFromFile();
} else if (choice1 == 9) {
calist.SaveInFile();
} else if (choice1 == 10) {
} else {
System.out.println("Invalid Input");
}
} while (choice1 != 10);
} else if (choice == 1) {
do {
System.out.print(
"=====Waiter=====\n[1] ShowList\n[2] Delete\n[3] Search\n[4] Sort\n[5] Clear\n[6] Undo\n[7] ADD\n[8] Read From File\n[9] Save In File\n[10] Exit\nEnter choice: ");
choice2 = input.nextInt();
if (choice2 == 1) {
calist.showList();
} else if (choice2 == 2) {
dWaiter = calist.deleteWaiter();
WaiterStack.push(dWaiter);
list.deleteWaiter(dWaiter.getWaiterID());
} else if (choice2 == 3) {
System.out.print("Enter name to search: ");
String name = input.next();
while (name.length() == 1) {
System.out.println("Name Invalid\nPlease Type Again: ");
name = input.next();
}
Waiter found = calist.searchName(name);
if (found == null)
System.out.println("Not in the list.");
else {
System.out.println(found.getName() + " " + found.getAge());
int searchMenu;
do {
System.out.print(
"MENU SEARCH\n====\n[1] NEXT\n[2] PREVIOUS\n[3] BACK\nEnter your choice: ");
searchMenu = inputSearchMenu.nextInt();
if (searchMenu == 1) {
found = calist.goToNext(found);
System.out.println(found.getName() + " " + found.getAge());
} else if (searchMenu == 2) {
found = calist.goToPrevious(found);
System.out.println(found.getName() + " " + found.getAge());
}
if (searchMenu == 3) {
}
} while (searchMenu != 3);
}
} else if (choice2 == 4) {
calist.sortList();
} else if (choice2 == 5) {
calist.clear();
} else if (choice2 == 6) {
Waiter a = WaiterStack.pop();
if (a == null)
System.out.println("Nothing to undo.");
else
calist.addWaiterStart(a.getAge(), a.getName(), a.getWaiterID());
} else if (choice2 == 7) {
System.out.print("\nName: ");
String name = input.next();
System.out.print("\nAge: ");
int age = input.nextInt();
System.out.print("\nId: ");
int id = input.nextInt();
while (calist.checkIDExsitance(id)) {
System.out.print("\nId Already Exist\nInput Again: ");
id = input.nextInt();
}
calist.addWaiterStart(age, name, id);
} else if (choice2 == 8) {
calist = calist.ReadFromFile();
} else if (choice2 == 9) {
calist.SaveInFile();
} else if (choice2 == 10) {
} else {
System.out.println("Invalid Input");
}
} while (choice2 != 10);
} else if (choice == 7777777) {
System.out.println("Cristiano Ronaldo Siuuuuuuuuuuuuuuuuuuuuu");
} else if (choice == 2) {
do {
System.out.print(
"Restaurant\n[1] Show Current List\n[2] Edit\n[3] ADD\n[4] Delete\n[5] Undo\n[6] Save in File\n[7] Read from File\n[8] Exit\nEnter choice: ");
choice3 = input.nextInt();
if (choice3 == 1) {
list.showList();
} else if (choice3 == 2) {// Havent Done Yet
list.showListTabNum();
System.out.print("Enter Table number: ");
int tableNum = input.nextInt();
while (!list.checkIDExsitance(tableNum)) {
System.out.print("ID does not Exist\nPlease try again: ");
tableNum = input.nextInt();
}
int choice32;
do {
System.out.print(
"-----Editing-----\n[1]Customer Login\n[2] Set Waiter\n[3] Order\n[4] Edit Bill\n[5] Exit");
choice32 = input.nextInt();
if (choice32 == 1) {
System.out.print("\nCustomer Id: ");
int id = input.nextInt();
culist.showList();
if (culist.checkIDExsitance(id)) {
if (list.checkCustomerExistence(culist.getCustomerByID(id))) {
System.out.println("ID already logged in");
} else {
list.setCustomer(culist.getCustomerByID(id), tableNum);
System.out.println("Succeeded");
}
} else {
System.out.print("New Customer Creating\nName: ");
String name = input.next();
while (name.length() == 1) {
System.out.println("Name Invalid\nPlease Type Again: ");
name = input.next();
}
System.out.print("\nAge: ");
int age = input.nextInt();
Customer newCustomer = new Customer(age, name, id, null);
culist.addCustomerEnd(newCustomer);
}
} else if (choice32 == 2) {
if (calist.isEmpty())
System.out.println("No Waiter Added Yet");
else {
System.out.print("Enter Waiter ID: ");
int WaiterID = input.nextInt();
if (calist.checkIDExsitance(WaiterID))
list.setWaiter(calist.getWaiterByID(WaiterID), tableNum);
else
System.out.println("ID not found");
}
} else if (choice32 == 3) {
Order(list.getRestaurantByTableNum(tableNum), menulist);
} else if (choice32 == 4) {
int choice244;
do {
System.out.println(
"-----Editing-----\n[1]Apply Discount \n[2] Set Date\n[3] Exit\nEnter Choice:");
choice244 = input.nextInt();
switch (choice244) {
case 1:
System.out.print("Enter Discount Percentage: ");
double percentage = input.nextDouble() / 100.0;
list.search(tableNum).getBill().setDiscount(percentage);
break;
case 2:
System.out.print("Enter Date: ");
String date = input.next();
list.search(tableNum).getBill().setDate(date);
break;
default:
break;
}
} while (choice244 != 2);
} else if (choice32 == 5) {
} else
System.out.println("Invalid Input");
} while (choice32 != 5);
} else if (choice3 == 3) {
if (calist.isEmpty()) {
System.out.print("No Waiter Yet\nAdd Waiter\n");
System.out.print("\nName: ");
String name = input.next();
while (name.length() == 1) {
System.out.println("Name Invalid\nPlease Type Again: ");
name = input.next();
}
System.out.print("\nAge: ");
int age = input.nextInt();
System.out.print("\nId: ");
int id = input.nextInt();
calist.addWaiterStart(age, name, id);
System.out.println("Waiter Added");
} else {
calist.showList();
System.out.print("Enter charged Waiter id: ");
int cid = input.nextInt();
if (calist.checkIDExsitance(cid)) {
System.out.print("Customer Login [Y/N]: ");
char clogin = input.next().charAt(0);
if (clogin == 'Y' || clogin == 'y') {
System.out.print("\nCustomer Id: ");
int id = input.nextInt();
culist.showList();
if (culist.checkIDExsitance(id)) {
if (list.checkCustomerExistence(culist.getCustomerByID(id))) {
System.out.println("ID already logged in");
} else {
System.out.print("\nEnter the table number");
int tableNumber = input.nextInt();
while (list.checkIDExsitance(tableNumber)) {
System.out.println("Table Number already exist.");
System.out.print("Input new Table Number: ");
tableNumber = input.nextInt();
}
list.addRestaurantEnd(tableNumber, calist.getWaiterByID(cid),
culist.getCustomerByID(id));
}
} else {
System.out.print("New Customer Creating\nName: ");
String name = input.next();
while (name.length() == 1) {
System.out.println("Name Invalid\nPlease Type Again: ");
name = input.next();
}
System.out.print("\nAge: ");
int age = input.nextInt();
culist.addCustomerStart(age, name, id);
System.out.print("Input the table number: ");
int tableNumber = input.nextInt();
while (list.checkIDExsitance(tableNumber)) {
System.out.println("Table Number already exist.");
System.out.print("Input new Table Number: ");
tableNumber = input.nextInt();
}
list.addRestaurantEnd(tableNumber, calist.getWaiterByID(cid),
culist.getCustomerByID(id));
}
} else if (clogin == 'N' || clogin == 'n') {
System.out.print("\nEnter the table number");
int tableNumber = input.nextInt();
while (list.checkIDExsitance(tableNumber)) {
System.out.println("Table Number already exist.");
System.out.print("Input new Table Number: ");
tableNumber = input.nextInt();
}
list.addRestaurantEnd(tableNumber, calist.getWaiterByID(cid));
} else {
do {
System.out.println("Invalid Input\nPlease try again: ");
clogin = input.next().charAt(0);
} while (clogin == 'Y' || clogin == 'y' || clogin == 'N' || clogin == 'n');
}
} else {
calist.showList();
System.out.println("ID does not exist.");
}
}
} else if (choice3 == 4) {
dRestaurant = list.deleteRestaurant();
rStack.push(dRestaurant);
} else if (choice3 == 5) {
Restaurant a = rStack.pop();
if (a == null)
System.out.println("Nothing to undo");
else
list.addRestaurantStart(a.getTableNumber(), a.getWaiter(), a.getCustomer());
} else if (choice3 == 6) {
list.SaveInFile();
} else if (choice3 == 7) {
list = list.ReadFromFile();
} else if (choice3 == 8) {
} else
System.out.println("Invalid Input");
} while (choice3 != 8);
} else if (choice == 3) {
int menuChoice;
do {
System.out.print(
"Menu Setting\n[1] Display\n[2] Add Items\n[3] Delete Items\n[4] Undo\n[5] Search\n[6] Save in File\n[7] Read From File\n[8] Exit\nEnter your choice: ");
menuChoice = input.nextInt();
if (menuChoice == 1) {
menulist.displayMenus();
} else if (menuChoice == 2) {
System.out.print("Enter Name: ");
String name = input.next();
System.out.print("\nEnter Price: ");
double price = input.nextDouble();
System.out.print("\nIs it available? (true/false): ");
boolean avail = input.nextBoolean();
System.out.print("\nEnter Category: ");
String category = input.next();
System.out.print("\nEnter Description: ");
String description = input.next();
System.out.print("\nEnter Preparation Time (in minutes): ");
int prepTime = input.nextInt();
System.out.print("\nIs it on sale? (true/false): ");
boolean isSale = input.nextBoolean();
System.out.print("\nEnter Sale Percentage (1 if none 0 if free): ");
double salePercentage = input.nextDouble();
System.out.print("\nEnter ID: ");
int id = input.nextInt();
if (menulist.checkIDExsitance(id)) {
System.out.print("ID already occupied: you may assigned a new ID to it: ");
id = input.nextInt();
while (menulist.checkIDExsitance(id)) {
System.out.print("ID already occupied: you may assigned a new ID to it: ");
id = input.nextInt();
}
}
menulist.addMenu(name, price, avail, category, description, prepTime, isSale, id,
salePercentage);
} else if (menuChoice == 3) {
System.out.print("Enter ID: ");
int dMenuID = input.nextInt();
delete = menulist.removeMenu(dMenuID);
menuStack.push(delete);
} else if (menuChoice == 4) {
if (menuStack.getSize() == 0)
System.out.println("Nothing to UNDO");
else {
Menu undo = menuStack.pop();
if (menulist.checkIDExsitance(undo.getId())) {
System.out.print("ID already occupied: you may assigned a new ID to it: ");
int newId = input.nextInt();
while (menulist.checkIDExsitance(newId)) {
System.out.print("ID already occupied: you may assigned a new ID to it: ");
newId = input.nextInt();
}
undo.setId(newId);
menulist.addMenu(undo);
} else
menulist.addMenu(undo);
}
} else if (menuChoice == 5) {
int searchChoice;
Menu temp;
System.out.print("====Search====\n[1] By Name\n [2] By ID [3] Exit\n Enter your choice: ");
searchChoice = input.nextInt();
do {
switch (searchChoice) {
case 1:
System.out.print("Enter Name: ");
String name = input.next();
temp = menulist.searchByName(name);
if (temp == null) {
System.out.println("Item Not Found");
} else {
int searchChoice1;
do {
System.out.print(
"Item Found\n[1] Set Name\n[2] Set Price\n[3] Set Availability\n[4] Set Category\n"
+
"[5] Set Description\n[6] Set Preparation Time\n[7] Set Sale Status\n[8] Set ID\n"
+
"[9] Set Sale Percentage\n[10] Exit\nChoose an option: ");
searchChoice1 = input.nextInt();
switch (searchChoice1) {
case 1:
System.out.print("\nEnter new name: ");
name = input.next();
temp.setName(name);
break;
case 2:
System.out.print("\nEnter new price: ");
double price = input.nextDouble();
temp.setPrice(price);
break;
case 3:
System.out.print("\nIs it available? (true/false): ");
boolean avail = input.nextBoolean();
temp.setAvail(avail);
break;
case 4:
System.out.print("\nEnter new category: ");
String category = input.next();
temp.setCategory(category);
break;
case 5:
System.out.print("\nEnter new description: ");
String description = input.next();
temp.setDescription(description);
break;
case 6:
System.out.print("\nEnter new preparation time: ");
int prepTime = input.nextInt();
temp.setPrepTime(prepTime);
break;
case 7:
System.out.print("\nIs it on sale? (true/false): ");
boolean isSale = input.nextBoolean();
temp.setSale(isSale);
break;
case 8:
System.out.print("\nEnter new ID: ");
int id = input.nextInt();
if (menulist.checkIDExsitance(id)) {
System.out.print(
"ID already occupied: you may assigned a new ID to it: ");
id = input.nextInt();
while (menulist.checkIDExsitance(id)) {
System.out.print(
"ID already occupied: you may assigned a new ID to it: ");
id = input.nextInt();
}
}
temp.setId(id);
break;
case 9:
System.out.print("\nEnter new sale percentage: ");
double salePercentage = input.nextDouble();
if (salePercentage >= 0)
temp.setSalePercentage(salePercentage);
else
System.out.println("Invalid Input");
break;
case 10:
break;
default:
System.out.println("\nInvalid option. Try again.");
}
input.nextLine();
} while (searchChoice1 != 10);
}
break;
case 2:
System.out.print("Enter ID: ");
int id = input.nextInt();
temp = menulist.searchByID(id);
if (temp == null) {
System.out.println("Item Not Found");
} else {
int searchChoice1;
do {
System.out.print(
"Item Found\n[1] Set Name\n[2] Set Price\n[3] Set Availability\n[4] Set Category\n"
+
"[5] Set Description\n[6] Set Preparation Time\n[7] Set Sale Status\n[8] Set ID\n"
+
"[9] Set Sale Percentage\n[0] Exit\nChoose an option: ");
searchChoice1 = input.nextInt();
switch (searchChoice1) {
case 1:
System.out.print("\nEnter new name: ");
name = input.next();
temp.setName(name);
break;
case 2:
System.out.print("\nEnter new price: ");
double price = input.nextDouble();
temp.setPrice(price);
break;
case 3:
System.out.print("\nIs it available? (true/false): ");
boolean avail = input.nextBoolean();
temp.setAvail(avail);
break;
case 4:
System.out.print("\nEnter new category: ");
String category = input.next();
temp.setCategory(category);
break;
case 5:
System.out.print("\nEnter new description: ");
String description = input.next();
temp.setDescription(description);
break;
case 6:
System.out.print("\nEnter new preparation time: ");
int prepTime = input.nextInt();
temp.setPrepTime(prepTime);
break;
case 7:
System.out.print("\nIs it on sale? (true/false): ");
boolean isSale = input.nextBoolean();
temp.setSale(isSale);
break;
case 8:
System.out.print("\nEnter new ID: ");
id = input.nextInt();
if (menulist.checkIDExsitance(id)) {
System.out.print(
"ID already occupied: you may assigned a new ID to it: ");
id = input.nextInt();
while (menulist.checkIDExsitance(id)) {
System.out.print(
"ID already occupied: you may assigned a new ID to it: ");
id = input.nextInt();
}
}
temp.setId(id);
break;
case 9:
System.out.print("\nEnter new sale percentage: ");
double salePercentage = input.nextDouble();
temp.setSalePercentage(salePercentage);
break;
case 10:
break;
default:
System.out.println("\nInvalid option. Try again.");
}
} while (searchChoice1 != 10);
}
break;
case 3:
break;
default:
System.out.println("Invalid Input");
;
}
} while (searchChoice != 3);
} else if (menuChoice == 6) {
menulist.SaveInFile();
} else if (menuChoice == 7) {
menulist = menulist.ReadFromFile();
} else if (menuChoice == 8) {
} else
System.out.print("Invalid Input");
} while (menuChoice != 8);
} else if (choice == 5) {
} else {
System.out.println("Invalid Input");
}
} while (choice != 5);
input.close();
fileS.close();
fileScanner.close();
inputSearchMenu.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void Order(Restaurant restaurant, MenuLL menulist) {
Scanner input = new Scanner(System.in);
int choice;
do {
System.out.print("------Ordering------\n[1] Add\n[2] Remove\n[3] Exit\nEnter your choice: ");
choice = input.nextInt();
if (choice == 1) {
System.out.print("Enter the Item ID: ");
menulist.displayMenus();
int id = input.nextInt();
restaurant.getBill().getMenu().addMenu(restaurant.getBill().getMenu().searchByID(id));
restaurant.getBill()
.setSubtotal(restaurant.getBill().getSubtotal() + menulist.searchByID(id).getPrice());
restaurant.getBill().setTotalNumOrderedFood(restaurant.getBill().getTotalNumOrderedFood() + 1);
} else if (choice == 2) {
menulist.displayMenus();
System.out.print("Enter the Item ID: ");
int id = input.nextInt();
if (restaurant.getBill().getMenu().checkIDExsitance(id)) {
{
restaurant.getBill().getMenu().removeMenu(id);
restaurant.getBill()
.setSubtotal(restaurant.getBill().getSubtotal() - menulist.searchByID(id).getPrice());
restaurant.getBill().setTotalNumOrderedFood(restaurant.getBill().getTotalNumOrderedFood() - 1);
}
} else
System.out.println("Item not found");
} else if (choice == 3) {
} else
System.out.println("Invalid Input");
} while (choice != 3);
input.close();
}
}