-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestaurant.java
2526 lines (2239 loc) · 93.1 KB
/
Restaurant.java
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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Class Name: Restaurant
Author: King Lai, ZiCheng Huang, John Oh, Nancy Hao
Date: January 10, 2019
School: A.Y. Jackson Secondary School
Purpose: This class loads restaurant information from textfiles, and
contains the run method which runs the entire program.
*/
import java.io.*;
import java.util.*;
import java.lang.reflect.Field;
public class Restaurant
{
//Encapsulation
// Constants
public static final int MONTHSPERYEAR = 12;
public static final int DAYSPERMONTH = 30;
public static final String MASTERKEY = "Ms.Lam";
public static final char WALL = 'W';
public static final char TAKEN = 'T';
public static final char FLOOR = '.';
public static final char TABLE = '*';
public static final char MARKEDTABLE = 'O';
public static final char TAKENTABLE = 'X';
public static final char DOOR = 'd';
public static final String SOFTWARENAME = "Fork and Knife";
public static final String VERSION = "1.2.7";
// Restaurant Information
private String name;
private int phoneNumber;
private String address;
private int horizontalLength;
private int verticalLength;
private double goldDiscount;
private double platDiscount;
private double tax;
private int doorRow;
private int doorColumn;
// Pseudo Constants
private int maxEmployee;
private int maxPossibleFoodsInCategory;
private int maxPossibleCategoriesInMenu;
private int maxCoupon;
private int maxPossibleFoodsInMenu;
// Restaurant Attributes
private char [][] map;
private Menu restaurantMenu;
private Date restaurantDate;
private Coupon[] couponDatabase; // Array of object
private Staff staff;
private ArrayList<Customer> customers; // Array of object
private Finance restaurantFinances;
private int numCoupons;
private int currentOrderNumber;
// Temporary Restaurant Attributes
private Order currentOrder;
private Coupon currentCoupon;
private Customer currentCustomer;
/*
Parameter(s): all the text file names
Description: This method is the constructor for the Restaurant class.
Purpose: Loads/creates restaurant information from text files,
and sets the respective fields to 0/null.
*/
public Restaurant (String restaurantInfoFileName, String employeeInfoFileName, String foodInfoFileName, String categoryInfoFileName,String floorPlanFileName, String couponFileName)
{
loadAllFiles(restaurantInfoFileName, employeeInfoFileName, foodInfoFileName, categoryInfoFileName, floorPlanFileName, couponFileName);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// METHODS RELATED TO LOADING
/*
Parameter(s): all the text file names
Description: This method reads in all the text file
Purpose: Loads/creates restaurant information from text files,
and sets the respective fields to 0/null.
*/
public void loadAllFiles(String restaurantInfoFileName, String employeeInfoFileName, String foodInfoFileName, String categoryInfoFileName,String floorPlanFileName, String couponFileName) {
if (loadRestaurant(restaurantInfoFileName)) { // Checks for errors in getting the restaurant information
// Setting temporary variables to 0/null
numCoupons = 0;
currentOrderNumber = 0;
currentOrder = null;
currentCoupon = null;
currentCustomer = null;
// Checks for errors in getting the category information
if (getAllCategories(categoryInfoFileName) == null) {
System.out.println("The system will now terminate.");
quit();
}
// Setting Restaurant attributes
restaurantMenu = new Menu(maxPossibleCategoriesInMenu, maxPossibleFoodsInCategory, getAllCategories(categoryInfoFileName));
map = new char [horizontalLength][verticalLength];
customers = new ArrayList<Customer>();
couponDatabase = new Coupon[maxCoupon];
staff = new Staff (maxEmployee);
/*
This tells that whether the user has inputted the correct information of text file
If not, it goes to quit option and ends the program
*/
if (!loadNumCategories(categoryInfoFileName)) {
System.out.println("\nThe system will now terminate.");
quit();
}
if (!loadMenu(foodInfoFileName)) {
System.out.println("\nThe system will now terminate.");
quit();
}
if (!loadEmployeeInfo(employeeInfoFileName)) {
System.out.println("\nThe system will now terminate.");
quit();
}
if (!loadFloorPlan(floorPlanFileName)) {
System.out.println("\nThe system will now terminate.");
quit();
}
if (!loadCoupon(couponFileName)) {
System.out.println("\nThe system will now terminate.");
quit();
}
restaurantFinances = new Finance (staff.getNumEmployees(), restaurantDate);
} else {
System.out.println("\nThe system will now terminate.");
quit();
}
// Delay after loading all files, and before booting up to the main screen
try {
Thread.sleep(100);
} catch (InterruptedException ite) {
System.out.println("\nThe system could not sleep. Continuing without delay.");
}
/*
Error trapping: if the Thread encounters an error on the backend side,
it will fail to sleep. This not an error related to the user.
*/
}
/*
Parameter(s):
- fileName: String file name of the Restaurant file
that contains the Restaurant information
Description: This method is used to load Restaurant information into the program.
Purpose: Sets the current date to -1 respectively, and try/catch loading
information of a Restaurant.
*/
public boolean loadRestaurant (String fileName)
{
int year = -1, month = -1, day = -1;
try
{
//File Input
BufferedReader in = new BufferedReader (new FileReader (fileName));
name = in.readLine();
phoneNumber = Integer.parseInt(in.readLine());
address = in.readLine();
maxEmployee = Integer.parseInt(in.readLine());
maxPossibleFoodsInCategory = Integer.parseInt(in.readLine());
maxPossibleCategoriesInMenu = Integer.parseInt(in.readLine());
maxCoupon = Integer.parseInt (in.readLine());
maxPossibleFoodsInMenu = Integer.parseInt (in.readLine());
horizontalLength = Integer.parseInt (in.readLine());
verticalLength = Integer.parseInt (in.readLine());
goldDiscount = Double.parseDouble (in.readLine());
platDiscount = Double.parseDouble (in.readLine());
tax = Double.parseDouble(in.readLine());
doorRow = Integer.parseInt (in.readLine());
doorColumn = Integer.parseInt (in.readLine());
year = Integer.parseInt(in.readLine());
month = Integer.parseInt(in.readLine());
day = Integer.parseInt(in.readLine());
restaurantDate = new Date(year, month, day);
in.close();
if (phoneNumber < 0 || maxEmployee < 0 || maxPossibleFoodsInCategory < 0 || maxPossibleCategoriesInMenu < 0 || maxCoupon < 0 || horizontalLength < 2 || verticalLength < 2 || goldDiscount <= 0 || goldDiscount >= 1
|| platDiscount <= 0 || platDiscount >= 1 || tax <= 0 || doorRow < 0 || doorRow >= verticalLength || doorColumn < 0 || doorColumn >= horizontalLength || month < 1 || month > 12 || day < 0 || day > 30) { // Logic error trapping
System.out.println("One or more restaurant info values are incorrect. Please double check the instructions and restart the program.");
System.out.println("\nThe program will now terminate.");
quit();
}
if (doorRow == 0 && doorColumn == 0 || doorRow == verticalLength - 1 && doorColumn == 0 || doorRow == 0 && doorColumn == horizontalLength - 1 || doorRow == verticalLength - 1 && doorColumn == horizontalLength - 1) { // Logic error trapping
System.out.println("The doors cannot be on corners of the floor plan. Please double check the instructions and restart the program.");
System.out.println("\nThe program will now terminate.");
quit();
}
System.out.println("Restaurant info loaded.");
return true;
}
catch (IOException iox) {
System.out.println("\nInvalid restaurant info file.");
return false;
} catch (NumberFormatException nfx) {
System.out.println("\nError loading the restaurant info file. Please check the file and restart the program.");
return false;
}
/*
Error trapping: if textfile cannot be found, it outputs an error message
if a String is tried to be converted into a non-String type, then it outputs an error message
*/
}
/*
Parameter(s):
- fileName: String file name of the Food Categories file
that contains all Category information
Description: This method is used to load Food Category information into the program.
Purpose: Try/catch loading Food Category information from the text file.
*/
private String[] getAllCategories(String fileName) {
try {
BufferedReader in = new BufferedReader(new FileReader(fileName));
int numCategories = Integer.parseInt(in.readLine());
if (numCategories < 1) { // Logic error trapping
System.out.println("\nThe number of categories that you have loaded is invalid. Please go back and set a valid number.");
System.out.println("\nThe program will now terminate.");
quit();
}
String[] categories = new String[numCategories];
for (int i = 0; i < numCategories; i++) {
categories[i] = in.readLine();
}
in.close();
System.out.println("Category information loaded.");
return categories;
} catch (IOException iox) {
System.out.println("\nInvalid category info file.");
return null;
} catch (NumberFormatException nfx) {
System.out.println("\nError loading the category info file. Please check the file and restart the program.");
return null;
}
/*
Error Trapping: returns error message if the file name cannot be read, also outputs error message if a String
value(not a number) was tried to converted into int.
*/
}
/*
Parameter(s):
- fileName: String file name of the Menu file
that contains the Menu information
Description: This method is used to load Menu information into the program.
Purpose: Try/catch loading Menu information from the text file.
*/
public boolean loadMenu (String fileName)
{
int numItem;
String name;
String ingredients;
String foodCategory;
double price;
int calories;
String description;
int availability;
double costToMake;
try
{
//File Input
BufferedReader in = new BufferedReader (new FileReader (fileName));
numItem = Integer.parseInt(in.readLine());
for (int i = 0; i < numItem; i++)
{
name = in.readLine();
ingredients = in.readLine();
foodCategory = in.readLine();
price = Double.parseDouble(in.readLine());
calories = Integer.parseInt(in.readLine());
description = in.readLine();
availability = Integer.parseInt(in.readLine());
costToMake = Double.parseDouble (in.readLine());
if (!restaurantMenu.addFood(name, ingredients, foodCategory, price, calories, description, availability, costToMake)) { // Logic error trapping
System.out.println(name + " could not be added due to invalid attributes.");
System.out.println("The program will continue without that food on the menu.\n");
}
}
in.close();
System.out.println("Menu file loaded.");
return true;
} catch (IOException iox) {
System.out.println("\nInvalid menu info file.");
return false;
} catch (NumberFormatException nfx) {
System.out.println("\nError loading the menu info file. Please check the file and restart the program.");
return false;
}
/*
Error trapping: if textfile cannot be found, it returns a error message
if the String is tried to converted into a non-String, then it outputs an error message
*/
}
/*
Parameter(s):
- fileName: String file name of the Food Category file
that contains the Restaurant information
Description: This method is used to load Food Category information into the program.
Purpose: Try/catch loading Food Category information from the text file.
*/
public boolean loadNumCategories(String categoryInfoFileName) {
try {
//File Input
BufferedReader in = new BufferedReader(new FileReader(categoryInfoFileName));
int numCategories = Integer.parseInt(in.readLine());
if (numCategories < 1) { // Logic error trapping
System.out.println("The number of categories that you have loaded is invalid. Please go back and set a valid number.");
System.out.println("\nThe program will now terminate.");
quit();
}
restaurantMenu.setNumCategories(numCategories);
System.out.println("Number of categories loaded.");
in.close();
return true;
} catch (IOException iox) {
System.out.println("\nInvalid category info file.");
return false;
} catch (NumberFormatException nfx) {
System.out.println("\nError loading the category info file. Please check the file and restart the program.");
return false;
}
/*
Error trapping: if textfile cannot be found, it returns a error message
if the String is tried to converted into a non-String, then it outputs an error message
*/
}
/*
Parameter(s):
- fileName: String file name of the employeeInfo file
that contains the Restaurant information
Description: This method is used to load Employee information into the program.
Purpose: Try/catch loading Employee information from the text file.
*/
public boolean loadEmployeeInfo (String fileName)
{
int numEmployee;
String name;
String occupation;
try
{
//File Input
BufferedReader in = new BufferedReader (new FileReader (fileName));
numEmployee = Integer.parseInt(in.readLine());
if (numEmployee > maxEmployee) { // Logic error trapping
numEmployee = maxEmployee;
System.out.println("\nWarning! You have more employees than the database can store.");
System.out.println("Employees up to the max limit were loaded, and the rest discarded.");
}
for (int i = 0; i < numEmployee; i++)
{
name = in.readLine();
occupation = in.readLine();
staff.addEmployee(name, occupation);
}
in.close();
System.out.println("Employee information loaded.");
return true;
} catch (IOException iox) {
System.out.println("\nInvalid employee info file.");
return false;
} catch (NumberFormatException nfx) {
System.out.println("\nError loading the employee info file. Please check the file and restart the program.");
return false;
}
/*
Error trapping: if textfile cannot be found, it returns a error message
if the String is tried to converted into a non-String, then it outputs an error message
*/
}
/*
Parameter(s):
- fileName: String file name of the Floor Plan file
that contains the map of how the restaurant looks like
Description: This method is used to load the floor plan into the program.
Purpose: Try/catch loading floor plan map from the text file.
*/
public boolean loadFloorPlan (String fileName)
{
try
{
//File Input
BufferedReader in = new BufferedReader (new FileReader (fileName));
for (int i = 0; i < horizontalLength; i++)
{
for (int j = 0; j < verticalLength; j++)
{
map [i][j] = (char)(in.read());
}
in.readLine();
}
in.close();
System.out.println("Floor plan loaded.");
return true;
} catch (IOException iox) {
System.out.println("\nInvalid floor plan file.");
return false;
} catch (NumberFormatException nfx) {
System.out.println("\nError loading the floor plan file. Please check the file and restart the program.");
return false;
}
/*
Error trapping: if textfile cannot be found, it returns a error message
if the String is tried to converted into a non-String, then it outputs an error message
*/
}
/*
Parameter(s):
- fileName: String file name of the Coupon file
that contains the Restaurant information
Description: This method is used to load Coupon information into the program.
Purpose: First creates pre-existing "empty" Coupon objects.
Then try/catch loading Coupon information from the text file.
*/
public boolean loadCoupon (String fileName) {
try {
//File Input
BufferedReader in = new BufferedReader (new FileReader (fileName));
this.numCoupons = Integer.parseInt(in.readLine());
if (this.numCoupons > maxCoupon) {
this.numCoupons = maxCoupon;
System.out.println("\nWarning! You have more coupons than the database can store.");
System.out.println("Coupons up to the max limit were loaded, and the rest discarded.");
}
for (int i = 0; i < this.numCoupons; i++) {
couponDatabase[i] = new Coupon();
couponDatabase[i].setCode(in.readLine());
double discount = Double.parseDouble(in.readLine());
if (discount <= 0 || discount >= 1) { // Logic error trapping: 0 < discounts < 1 is the range of allowed parameters
System.out.println("One of the coupons has an unusual discount. Please close the program and double check.");
System.out.println("\nThe program will now terminate.");
quit();
} else {
couponDatabase[i].setDiscount(discount);
}
}
in.close();
System.out.println("Coupon information loaded.");
return true;
} catch (IOException iox) {
System.out.println("\nInvalid coupon info file.");
return false;
} catch (NumberFormatException nfx) {
System.out.println("\nError loading the coupon info file. Please check the file and restart the program.");
return false;
}
/*
Error trapping: if textfile cannot be found, it returns a error message
if the String is tried to converted into a non-String, then it outputs an error message
*/
}
// METHODS RELATED TO LOADING
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// METHODS RELATED TO RUNNING
/*
Description: This method is used to run the entire program.
Purpose: All functionalities are tied to the run method
of the Restaurant class.
*/
public void run() throws InterruptedException
{
if (!areWallsOnSides()) { // Check if the floor plan is in the correct format
System.out.println("\nEither walls do not surround the restaurant, or the doors are not quite correct.");
System.out.println("Please shut down the program and follow the instruction manual on how to set up the floor plan.!");
System.out.println("The system will now terminate.");
quit();
}
// Check if tables are placed properly (not blocked)
if (!isAllTablesAccessible()) {
System.out.println("\nWarning! Some tables are blocked and cannot be accessed. ");
System.out.println("Please shut down the program and move your tables around!");
System.out.println("The system will now terminate.");
quit();
}
// Check if the menu is empty
if (restaurantMenu.isMenuEmpty()) {
System.out.println("\nWarning! The restaurant does not have any food items on the menu. ");
System.out.println("Please shut down the program and add some food.");
System.out.println("The system will now terminate.");
quit();
}
System.out.print ("\n-");
Thread.sleep(100);
for (int i = 0; i < 60; i++) {
System.out.print ("-");
Thread.sleep(20);
}
System.out.println("\n\nWelcome to " + SOFTWARENAME + "!\n");
runOption();
}
// METHODS RELATED TO RUNNING
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// METHODS RELATED TO MENU SCREENS
/*
Description: This method is used to display the very beginning of the program after the loading is finished.
Purpose: Display choices where the user can input which
option they want to move forward with.
*/
public void runOption() {
String[] initialMenuChoices = {"Start", "Help", "Quit"};
Options initialMenu = new Options (initialMenuChoices);
initialMenu.printAllOptions();
int userInput = initialMenu.getUserInput();
if (userInput == 1)
startOption();
else if (userInput == 2)
helpOption();
else
quit();
}
/*
Description: This method is used to display the start of the program.
Purpose: Display choices where the user can input which
option they want to move forward with.
*/
public void startOption ()
{
String[] startMenuChoices = {"Customer", "Owner", "Quit"};
Options startMenu = new Options(startMenuChoices);
startMenu.printAllOptions ();
int startMenuUserInput = startMenu.getUserInput();
if (startMenuUserInput == 1)
landingOption(true);
else if (startMenuUserInput == 2)
ownerOption();
else
quit();
}
/*
Description: This method is used to display the help options.
Purpose: Educates the user on what this program does, and how to choose an Option.
*/
public void helpOption ()
{
//This help option informs the user of what the program does
Scanner sc = new Scanner (System.in);
System.out.println ("This program allows you to:");
System.out.println("Customer:");
System.out.println ("\t- view our restaurant menu");
System.out.println ("\t- add food(s) to an order");
System.out.println ("\t- purchase a gold or platinum membership with respective benefits");
System.out.println ("\t- checkout with coupon options");
System.out.println ("\t- order takeout or dine in the restaurant");
System.out.println("Owner: ");
System.out.println ("\t- Add food to the existing menu");
System.out.println ("\t- Delete food from the existing menu");
System.out.println ("\t- View the current and past restaurant portfolio");
System.out.println ("\t- Manage the staff members");
System.out.println ("\t- Manage the current date");
System.out.println ("\nTo choose an option, an input of a single digit will activate the corresponding step.");
System.out.println ("If bad data in entered, this program will loop until good data is entered.");
System.out.print ("\nPlease press any key to return back to the main menu: ");
sc.nextLine();
System.out.println();
startOption();
}
/*
Description: This method is used to display the owner options.
Purpose: Display the choices exclusively only the owner has access to
*/
public void ownerOption() {
printHeader("OWNER OPTIONS");
String[] ownerChoices = {"Add Food Item", "Remove Food Item", "Restaurant Business", "Manage Staff", "Manage Inventory", "Manage Date", "Go Back"};
Options ownerMenu = new Options(ownerChoices);
ownerMenu.printAllOptions();
int userInput = ownerMenu.getUserInput();
if (userInput == 1)
addFoodItemOption();
else if (userInput == 2)
removeFoodItemOption();
else if (userInput == 3)
viewRestaurantBusiness();
else if (userInput == 4)
employeeOption();
else if (userInput == 5)
manageInventoryOption();
else if (userInput == 6)
manageDateOption();
else
startOption();
}
/*
Description: This method is the option to add an item onto the menu.
Purpose: Reads in input of fields of a Food object, and adds the
item under the correct Food Category. If there are any errors
made, the user can be warped back.
*/
public void addFoodItemOption() {
addFoodItem();
}
/*
Description: This method is the option to remove an itemon the menu.
Purpose: Reads in input from the user on which Food do delete. If there
are any errors, the user can be warped back.
*/
public void removeFoodItemOption() {
removeFoodItem();
}
/*
Description: This method is used to display the Employee options.
Purpose: Displays the choices of which an employee can choose
which option they would like to proceed with.
*/
public void employeeOption() {
printHeader("MANAGE STAFF");
String[] employeeChoices = {"Add Employee", "Remove Employee", "View All Employees", "Go Back"};
Options employeeMenu = new Options(employeeChoices);
employeeMenu.printAllOptions();
int userInput = employeeMenu.getUserInput();
if (userInput == 1)
addEmployee();
else if (userInput == 2)
removeEmployee();
else if (userInput == 3)
listAllEmployees();
else
ownerOption();
}
/*
Description: This method is the option to manage the inventory.
Purpose: Displays the choices of which an Owner can choose
to restock the quantity of an item or liquify one.
*/
public void manageInventoryOption() {
printHeader("MANAGE INVENTORY");
String[] manageInventoryChoices = {"Restock an Item", "Liquify an Item", "Go Back"};
Options manageInventoryMenu = new Options(manageInventoryChoices);
manageInventoryMenu.printAllOptions();
int userInput = manageInventoryMenu.getUserInput();
if (userInput == 1)
changeAvailability(true);
else if (userInput == 2)
changeAvailability(false);
else
ownerOption();
}
/*
Description: This method is used to display the date options for the user.
Purpose: This allows the owner to update the information of the restaurant date.
*/
public void manageDateOption () {
Scanner sc = new Scanner (System.in);
printHeader("MANAGE DATE");
//tells the owner today's date
System.out.println ("Current date is " + restaurantDate);
String [] manageDateChoices = {"Go To Next Day", "Set Custom Date", "Go Back"};
Options manageDateMenu = new Options (manageDateChoices);
manageDateMenu.printAllOptions();
int userInput = manageDateMenu.getUserInput();
if (userInput == 1)
goToNextDay();
else if (userInput == 2)
setCustomDate();
else
ownerOption();
}
/*
Description: This method creates a new current order
Purpose: This method creates an order for new customer.
*/
public void landingOption (boolean newOrderNumber)
{
Scanner sc = new Scanner (System.in);
System.out.println ("Welcome to " + name + "!\n");
if (newOrderNumber) {
currentOrderNumber = generateOrderNumber();
}
currentOrder = new Order (currentOrderNumber, restaurantDate, maxPossibleFoodsInMenu, tax);
currentCoupon = new Coupon();
currentCustomer = null;
String[] landingChoices = {"Become a Premium Customer", "Continue To View Menu", "Go Back"};
Options landingMenu = new Options (landingChoices);
landingMenu.printAllOptions();
int landingPageUserInput = landingMenu.getUserInput();
if (landingPageUserInput == 1)
chooseCustomerOption();
else if (landingPageUserInput == 2)
displayFoodCategoryOption();
else {
System.out.print ("Enter protected password: ");
String userInput = sc.nextLine();
if (userInput.equals (MASTERKEY)) {
System.out.println("Master key entered successfully.\n");
startOption();
}
else {
System.out.println("Master key entered unsuccessfully. Going back to welcome screen.\n");
landingOption(false);
}
}
}
/*
Description: This method is used to display the possible choices of being a special customer.
Purpose: To give a chance for customer to become a special customer and have different discounts.
*/
public void chooseCustomerOption() {
printHeader("BECOME A PREMIUM CUSTOMER");
String[] chooseCustomerChoices = {"Gold Customer", "Platinum Customer", "Go Back"};
Options chooseCustomerMenu = new Options (chooseCustomerChoices);
chooseCustomerMenu.printAllOptions();
int chooseCustomerUserInput = chooseCustomerMenu.getUserInput();
if (chooseCustomerUserInput == 1)
newCustomerCredentialsOption(1);
else if (chooseCustomerUserInput == 2)
newCustomerCredentialsOption(2);
else
landingOption(false);
}
/*
Parameter(s):
- customerType: an integer that will correspond whether the choice
was to create a Gold or Platinum Customer.
Description: This method grants the ability to create either a Gold or Platinum Customer.
Purpose: Reads in a Customer username and password, and moves
on to display the Food Category options.
*/
public void newCustomerCredentialsOption(int customerType) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter new username: ");
String customerID = sc.nextLine();
System.out.print("Enter new password: ");
String password = sc.nextLine();
if (customerType == 1)
newGoldCustomer(customerID, password);
else if (customerType == 2)
newPlatCustomer(customerID, password);
}
/*
Description: This method is the option to display all the Food Categories.
Purpose: Displays all the Category choices which the Customer can choose from to proceed.
*/
public void displayFoodCategoryOption ()
{
Scanner sc = new Scanner(System.in);
System.out.println ("FOOD CATEGORIES:");
String [] displayOptions = new String[restaurantMenu.getNumCategories() + 2];
for (int i = 0; i < displayOptions.length-2; i++)
displayOptions[i] = restaurantMenu.getCategoryList()[i].getCategoryName();
displayOptions[displayOptions.length - 2] = "Proceed To Pay";
displayOptions[displayOptions.length - 1] = "Cancel Order";
Options displayMenu = new Options(displayOptions);
displayMenu.printAllOptions();
int userInput = displayMenu.getUserInput();
if (userInput >= 1 && userInput <= restaurantMenu.getNumCategories())
displayFoodOption(userInput);
else if (userInput == displayOptions.length - 1)
{
if (currentOrder.getNumItems() > 0)
paymentOption();
else {
System.out.print("You have no items ordered. Press any key to go back to the menu: ");
sc.nextLine();
System.out.println();
displayFoodCategoryOption();
}
}
else
landingOption(false);
}
/*
Parameter(s):
- categoryIndexPlusOne: the Category index inputted from
the displayFoodCategoryOption added by 1
Description: This method is the option to display all the Food items.
Purpose: Using the categoryIndexPlusOne index, will display all the Food items
of the index minus 1, and reads in which Food option the user chooses.
*/
public void displayFoodOption(int categoryIndexPlusOne)
{
Scanner sc = new Scanner(System.in);
System.out.println ("FOOD CHOICES");
String [] displayOptions = new String[restaurantMenu.getCategoryList()[categoryIndexPlusOne - 1].getNumFood() + 2];
for (int i = 0; i < displayOptions.length-2; i++)
displayOptions[i] = restaurantMenu.getCategoryList()[categoryIndexPlusOne - 1].getFoodItems()[i].getFoodName();
displayOptions[displayOptions.length - 2] = "Proceed To Pay";
displayOptions[displayOptions.length - 1] = "Go Back";
Options displayMenu = new Options(displayOptions);
displayMenu.printAllOptions();
int userInput = displayMenu.getUserInput ();
if (userInput >= 1 && userInput <= restaurantMenu.getCategoryList()[categoryIndexPlusOne - 1].getNumFood())
foodOption(userInput, categoryIndexPlusOne);
else if (userInput == displayOptions.length - 1)
{
if (currentOrder.getNumItems() > 0)
paymentOption();
else {
System.out.println("You have no items ordered. Press any key to go back to the menu: ");
sc.nextLine();
System.out.println();
displayFoodCategoryOption();
}
}
else
{
System.out.println();
displayFoodCategoryOption();
}
}
/*
Parameter(s):
- categoryIndexPlusOne: the Category index inputted from displayFoodCategoryOption added by 1
- foodIndexPlusOne: the Food index inputted from displayFoodOption added by 1
Description: This method is the option to display all the Food options.
Purpose: Displays options where the Customer can add it to their order or proceed to pay.
*/
public void foodOption (int foodIndexPlusOne, int categoryIndexPlusOne)
{
Scanner sc = new Scanner(System.in);
System.out.println (restaurantMenu.getCategoryList()[categoryIndexPlusOne - 1].getFoodItems()[foodIndexPlusOne - 1]);
System.out.println("Current availability: " + restaurantMenu.getCategoryList()[categoryIndexPlusOne - 1].getFoodItems()[foodIndexPlusOne - 1].getAvailability() + "\n");
String [] mainOptions = {"Add To Order", "Proceed To Pay", "Go Back"};
Options foodMenu = new Options(mainOptions);
foodMenu.printAllOptions();
int userInput = foodMenu.getUserInput();
if (userInput == 1)
addOrderOption (categoryIndexPlusOne, foodIndexPlusOne);
else if (userInput == 2)
{
if (currentOrder.getNumItems() > 0)
paymentOption();
else {
System.out.println("You have no items ordered. Press any key to go back to the menu: ");
sc.nextLine();
System.out.println();
displayFoodCategoryOption();
}
}
else
displayFoodOption (categoryIndexPlusOne);
}
/*
Parameter(s):
- categoryIndexPlusOne: the Category index inputted from displayFoodCategoryOption added by 1
- foodIndexPlusOne: the Food index inputted from displayFoodOption added by 1
Description: This method is the Option to add it to an Order.
Purpose: Reads the amount wanted, adds it to their Order, and subtracts the quantity from the menu.
*/
public void addOrderOption (int categoryIndexPlusOne, int foodIndexPlusOne)
{
Scanner sc = new Scanner (System.in);
int quantity = -1; // -1 is temporary, it will either be caught in the try/catch or a user input value will be fetched
System.out.print ("Enter amount wanted: ");
try {
quantity = sc.nextInt();
sc.nextLine();
} catch (InputMismatchException imx) {
sc.nextLine();
System.out.print("\nPlease enter a valid number. Press any key to order again: ");
sc.nextLine();
System.out.println();
foodOption(categoryIndexPlusOne, foodIndexPlusOne);
}
/*
Error Trapping: it returns error message if the user's input doesn't match the variable's datatype
*/
if (quantity > 0) {
System.out.println();
Food menuFood = restaurantMenu.getCategoryList()[categoryIndexPlusOne - 1].getFoodItems()[foodIndexPlusOne - 1];
Food orderFood = new Food (menuFood.getFoodName(), menuFood.getIngredient(), menuFood.getFoodCategory(), menuFood.getPrice(), menuFood.getCalories(), menuFood.getDescription(), menuFood.getAvailability(), menuFood.getCostToMake());
addFoodToOrder(menuFood, orderFood, quantity, categoryIndexPlusOne, foodIndexPlusOne);
} else {
System.out.println("\nPlease enter a valid number. Press any key to order again: ");
sc.nextLine();
System.out.println();
foodOption(categoryIndexPlusOne, foodIndexPlusOne);
}
}
/*
Description: This method is the Option finalize an Order.
Purpose: Displays options where the Customer can add
more to their Order or proceed to checkout.
*/
public void paymentOption ()
{
String [] paymentOption = {"Add More Order", "Proceed To Checkout"};
Options paymentMenu = new Options (paymentOption);
paymentMenu.printAllOptions();
int userInput = paymentMenu.getUserInput();
if (userInput == 1)
displayFoodCategoryOption();
else if (userInput == 2)
checkoutOption();
}
/*