This repository was archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOS.java
More file actions
2996 lines (2775 loc) · 240 KB
/
POS.java
File metadata and controls
2996 lines (2775 loc) · 240 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
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
import java.io.*;
public class POS {
// [Menu Items]
static String[] Burger_Sandwich = { "Regular Burger", "Bacon cheeseburger", "Chicken burger", "Hotdog sandwich",
"Tuna sandwich" };
static String[] Meals = { "Chicken", "Burger Steak", "Sisig", "Spaghetti", "Palabok" };
static String[] Drinks = { "Coke", "Sprite", "Fanta", "Purified Water", "Lemonade", "Nestea" };
static String[] Desserts = { "Ice cream", "Sundaes", "Shakes" };
static String[] Extras = { "Fries", "pies", "Potato wedges" };
// [Menu Prices]
static double[] Burger_Sandwich_Price = { 35.00, 100.00, 50.00, 55.00, 70.00 };
static double[] Meals_Price = { 99.00, 75.00, 70.00, 65.00, 65.00 };
static double[] Drinks_Price = { 14.00, 14.00, 16.00, 0.00, 16.00, 18.00 };
static double[] Desserts_Price = { 15.00, 25.00, 35.00 };
static double[] Extras_Price = { 50.00, 50.00, 50.00 };
// [Menu Quantity]
static int[] Burger_Sandwich_Stock = { 25, 25, 25, 25, 25 };
static int[] Meals_Stock = { 25, 25, 25, 25, 25 };
static int[] Drinks_Stock = { 50, 50, 50, 50, 50, 50 };
static int[] Desserts_Stock = { 15, 15, 15 };
static int[] Extras_Stock = { 10, 10, 10 };
// [user ordered items]
static int[] Burger_Sandwich_Order = { 0, 0, 0, 0, 0 };
static int[] Meals_Order = { 0, 0, 0, 0, 0 };
static int[] Drinks_Order = { 0, 0, 0, 0, 0, 0 };
static int[] Desserts_Order = { 0, 0, 0 };
static int[] Extras_Order = { 0, 0, 0 };
// [User Choices]
static int[] Burger_Sandwich_Choice = { 0, 0, 0, 0, 0 };
static int[] Meals_Choice = { 0, 0, 0, 0, 0 };
static int[] Drinks_Choice = { 0, 0, 0, 0, 0, 0 };
static int[] Desserts_Choice = { 0, 0, 0 };
static int[] Extras_Choice = { 0, 0, 0 };
static int choice = 0;
static int Payment_Options = 0;
static String name = "";
static boolean end_program = false;
static boolean Return_from_Transaction = false;
static boolean Return_to_Order = false;
static boolean Trans_to_menu = false;
static int[] Product_Total_Price = { 0, 0, 0, 0, 0 };
// [Overall Total]
static double Subtotal = 0;
static double Tax = 0.10;
static double Total = 0;
static double cash = 0;
static double change = 0;
static boolean[] Soldout = { false, false, false, false, false };
static boolean[] Check_for_Order = { false, false, false, false, false };
static boolean[] Empty_Choice = { true, true, true, true, true };
static boolean[] Return_Empty_Category = { true, true, true, true, true };
// change to true if you run it on cmd, else false if you run it on Terminal
// that supports ANSI escape codes
static boolean EnableforCMD = true;
/*
* It only appears if the method has a function called try-catch
* "G4" - Group number | "M" - Method | 1 - 1st Method
* -------------------------------------------------------------
* Menu Error - G4M3
* Category Error - G4M4
* transaction Error - G4M6
* return Error - G4M10
*/
public static void main(String[] args) throws IOException, InterruptedException {
BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
// add 5 columns to the terminal with a 9 space between each column
// to align the menu items
String format = "%1$-10s %2$-10s %3$-10s %4$-10s %5$-10s";
/*
* %1$ is the first column, etc.
* -9s is the width of the column, 9 is for how many
* character before the next column
*/
// Clear the screen
// NOTE: [\033\143] only works on terminals that support ANSI escape codes
// like windows termnal, linux terminal, onlinegdb.com
// System.out.println("\033\143");
clearConsole();
// calling Information method
Information();
// ask the user to enter their name
System.out.println("\n\n");
System.out.print("Please enter your name: ");
name = breader.readLine().toUpperCase();
clearConsole();
// add 4 blank lines to the terminal
System.out.println("\n\n\n\n\n");
// print welcome message with the user's name
System.out.println(String.format(format, "", "", "Welcome " + name + "!", "", ""));
System.out.println("\n\n\n\n\n");
// Delay the program for 1.9 seconds
// the Thread.sleep() is using the milliseconds as the unit
Thread.sleep(1900);
clearConsole();
// calling the Menu method
Menu();
}
public static void Information() throws InterruptedException {
// NOTE: This method is for esthetic purposes only
String format = "%1$-10s %2$-13s %3$-3s %4$-23s";
// List of Members
String[] members = { "Ryan James V. Capadocia", "James Matthew Veloria", "Joseph Contador",
"Trina Mae Par ", "Lorenzo Asis", "Cesar Isaac" };
// other information
String Prof = "Ms. Mariella Leyba";
String Sub = "DCIT23A";
String Proj = "Point of Sale";
// if end_program is false, print the welcome message
if (end_program == false) {
System.out.println("+---------------------- WELCOME --------------------+");
} else {
System.out.println("+---------------------------------------------------+");
}
// print the information
System.out.println("| Group 4 [Fast Food Point of Sale] |");
System.out.println("+---------------------------------------------------+");
System.out.println("_____________________________________________________");
System.out.println(String.format(format, "Instructor", "", "", Prof));
System.out.println(String.format(format, "Subject", "", "", Sub));
System.out.println(String.format(format, "Project", "", "", Proj));
System.out.println("-----------------------------------------------------");
Thread.sleep(1000);
System.out.println(":=========[ Group Leader ]==========================:");
System.out.println(String.format(format, "", "", "", members[0]));
// loop through the members array and print the rest of the members except the
// first one
System.out.println(":=========[ Group Members ]=========================:");
for (int i = 1; i < members.length; i++) {
System.out.println(String.format(format, "", "", "", members[i]));
Thread.sleep(300);
}
System.out.println("-----------------------------------------------------");
// if end_program is false, the program loading will be displayed
if (end_program == false) {
for (int i = 1; i <= 100; i++) {
System.out.print("\rPlease Wait while we load the Program: " + i + " %");
// random number from 1 to 150 to simulate the loading
int random = (int) (Math.random() * 150) + 1;
// asign the random number to the sleep time
Thread.sleep(random);
}
clearConsole();
System.out.println("+---------------------------------------------------+");
System.out.println("| DONE |");
System.out.println("+---------------------------------------------------+");
// Delay the program for 1 millisecond or 1 second
Thread.sleep(1000);
clearConsole();
} else {
clearConsole();
System.out.println("+---------------------------------------------------+");
System.out.println("| GOOD-BYE |");
System.out.println("+---------------------------------------------------+");
Thread.sleep(1800);
clearConsole();
}
}
public static void Menu() throws IOException, InterruptedException {
BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
String format = "%1$-21s %2$-10s %3$-20s";
// try-catch block to catch the error if the user enters a wrong input
try {
System.out.println("+---------------------------------------------------+");
System.out.println("| MENU |");
System.out.println("+---------------------------------------------------+");
System.out.println("\nPlease select the category you want to buy from\n");
// if Soldout is true for the first category, print the category name and
// Soldout
// same for the other categories
if (Soldout[0] == true) {
System.out.println(String.format(format, "[ 1 ] Burger/Sandwich", "(Sold Out)", ""));
} else {
System.out.println(String.format(format, "[ 1 ] Burger/Sandwich", "", ""));
}
if (Soldout[1] == true) {
System.out.println(String.format(format, "[ 2 ] Meals", "(Sold Out)", ""));
} else {
System.out.println(String.format(format, "[ 2 ] Meals", "", ""));
}
if (Soldout[2] == true) {
System.out.println(String.format(format, "[ 3 ] Drinks", "(Sold Out)", ""));
} else {
System.out.println(String.format(format, "[ 3 ] Drinks", "", ""));
}
if (Soldout[3] == true) {
System.out.println(String.format(format, "[ 4 ] Desserts", "(Sold Out)", ""));
} else {
System.out.println(String.format(format, "[ 4 ] Desserts", "", ""));
}
if (Soldout[4] == true) {
System.out.println(String.format(format, "[ 5 ] Extra", "(Sold Out)", ""));
} else {
System.out.println(String.format(format, "[ 5 ] Extra", "", ""));
}
System.out.println(String.format(format, "", "", "--------------------"));
// this return item category will only show if the user have ordered
for (int i = 0; i < Check_for_Order.length; i++) {
if (Check_for_Order[i] == true) {
System.out.println(String.format(format, "", "", "[ 6 ] Return an Item"));
break;
}
}
// same as return item category, this will only show if the user have soldout an
// category
for (int i = 0; i < Soldout.length; i++) {
if (Soldout[i] == true) {
System.out.println(String.format(format, "", "", "[ 7 ] Checkout"));
break;
}
}
System.out.println(String.format(format, "", "", "[ 0 ] Exit"));
// prompt the user to enter the category number
System.out.println("-----------------------------------------------------");
System.out.print("Enter your choice: ");
choice = Integer.parseInt(breader.readLine());
clearConsole();
// after the user enter the category number, the program will go to the
// corresponding method
Category(choice);
} catch (Exception e) {
clearConsole();
System.out.println("-----------------------------------------------------");
System.out.println("Error " + e.getMessage());
System.out.println("Error Code: [G4M3]");
System.out.println("-----------------------------------------------------");
System.out.println("You can only enter a numeric value between 0-7");
Thread.sleep(3000);
clearConsole();
Menu();
}
}
public static void Category(int choice) throws IOException, InterruptedException {
BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
String format = "%1$-4s %2$-18s %3$-3s %4$-12s %5$-5s %6$-3s";
try {
switch (choice) {
case 0:
clearConsole();
System.out.println("+---------------------------------------------------+");
System.out.println("| Thank you for using our program |");
System.out.println("+---------------------------------------------------+");
Thread.sleep(1000);
end_program = true;
Information();
break;
case 1:
// before the user can order the item, the program will check if the category is
// soldout
if (Burger_Sandwich_Stock[0] == 0 && Burger_Sandwich_Stock[1] == 0 &&
Burger_Sandwich_Stock[2] == 0 &&
Burger_Sandwich_Stock[3] == 0 &&
Burger_Sandwich_Stock[4] == 0) {
Soldout[0] = true;
// if the category is soldout, the program will display the Soldout
// message
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| This item is sold out |");
System.out.println(
"+---------------------------------------------------+\n");
// prompt the user if they want to order more item
System.out.print("Do you want to add more items? (Y/N): ");
String add = breader.readLine();
// if the user enter Y, the program will go to the Menu method
// NOTE: this add String is not case sensitive so the user can enter Y
// or y
if (add.equalsIgnoreCase("Y")) {
clearConsole();
Menu();
// if the user enter N, the program will go to the Receipt
// method to process the order
} else if (add.equalsIgnoreCase("N")) {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Thank you Please wait while we process your order |");
System.out.println(
"+---------------------------------------------------+");
// Random delay between 0.1 to 2 seconds
int random = (int) (Math.random() * (2000 - 100 + 1) + 100);
Thread.sleep(random);
Order_List();
// if the user enter any other input,
// the program will display the error message and go back to the
// Last choice user choose
} else {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| You can only enter Y or N |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
Category(choice);
}
} else {
// this will display the category name
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Burger/Sandwich |");
System.out.println(
"+---------------------------------------------------+\n");
// this will display the item name, price, and stock
System.out.println(String.format(format, "", "Item", "", "Qty", "Price",
""));
System.out.println(
"-----------------------------------------------------");
for (int i = 0; i < Burger_Sandwich.length; i++) {
if (Burger_Sandwich_Stock[i] == 0) {
// if the specific item Stock is 0, the program will
// display the Soldout message
System.out.println(String.format(format, "[" + (i + 1) +
"] ", Burger_Sandwich[i], "-",
"Out of Stock", "", ""));
} else if (Burger_Sandwich_Price[i] == 0.0) {
// If the specific item price is 0.0, the program will
// display the free message
System.out.println(String.format(format, "[" + (i + 1) +
"] ", Burger_Sandwich[i], "-",
Burger_Sandwich_Stock[i], "Free", ""));
} else {
// if the item price or Stock is not 0, the program will
// display the item name,
// Stock and price
System.out.println(String.format(format, "[" + (i + 1) +
"] ", Burger_Sandwich[i], "-",
Burger_Sandwich_Stock[i],
Burger_Sandwich_Price[i], "Php"));
}
}
System.out.println(String.format(format, "", "", "", "", "------------",
""));
System.out.println(String.format(format, "", "", "", "", "[0] Back",
""));
System.out.println(
"_____________________________________________________");
// prompt the user to enter choice
System.out.print("Enter your choice: ");
int Bs_choice = Integer.parseInt(breader.readLine());
// set the index to user choice - 1
// ex: if the user choose 1, the index will be 0 to access the first
// item
int index = Bs_choice - 1;
// set the Bs_quantity to 0
int Bs_quantity = 0;
// if the user enter 0, the program will go to the Menu method
if (Bs_choice == 0) {
clearConsole();
Menu();
} else {
// the program will check if the user enter a smaller or equal
// to the list of item
if (Bs_choice <= Burger_Sandwich.length) {
// if the item is soldout, the program will display the
// Out of Stock message
if (Burger_Sandwich_Stock[index] == 0) {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Sorry, the item you selected is Out of Stock |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
// after the message is displayed, the program
// will go back to the Category 1
Category(1);
} else {
// if the item is not soldout, the program will
// display the item name,
clearConsole();
System.out.println(
"----------------- You have selected -----------------");
System.out.println(String.format(format, "",
"Item", "", "Qty", "Price",
""));
System.out.println(
"-----------------------------------------------------");
System.out.println(String.format(format, "",
Burger_Sandwich[index], "",
Burger_Sandwich_Stock[index],
Burger_Sandwich_Price[index],
"Php"));
System.out.println(
"-----------------------------------------------------");
System.out.print(
"Enter the quantity you want to buy: ");
Bs_quantity = Integer.parseInt(breader
.readLine());
// if the user enter a bigger number than the
// Stock,
// the program will display the available Stock
// and go back to the Category 1
if (Bs_quantity > Burger_Sandwich_Stock[index]) {
clearConsole();
System.out.println(
"-----------------------------------------------------");
System.out.println(
"Sorry, we only have [" +
Burger_Sandwich_Stock[index] +
"] " +
Burger_Sandwich[index] +
" in stock");
System.out.println(
"-----------------------------------------------------");
Thread.sleep(2000);
clearConsole();
Category(1);
} else {
// if the user enter a smaller or equal
// to the Stock, the item will be bought
clearConsole();
System.out.println(
"-----------------------------------------------------");
System.out.println("You ordered [" +
Bs_quantity + "] " +
Burger_Sandwich[index] +
"");
// add 1 to the catergory choice to
// recored the item that the user choose
Burger_Sandwich_Choice[index]++;
// the Bs_quantity will be subtracted
// from the Stock
Burger_Sandwich_Stock[index] -= Bs_quantity;
// the Bs_quantity will be Added to the
// order
Burger_Sandwich_Order[index] += Bs_quantity;
// set the check for order to true
Check_for_Order[0] = true;
// prompt the user to enter the next
// choice
System.out.println(
"-----------------------------------------------------");
System.out.print(
"[1] Add more items\n[2] Choose a different category\n[0] Checkout\n");
System.out.println(
"_____________________________________________________");
System.out.print("Enter your choice: ");
int add = Integer.parseInt(breader
.readLine());
// if the user enter 1, the program will
// go to the Category 1
if (add == 1) {
clearConsole();
Category(1);
// if the user enter 2, the
// program will go to menu
} else if (add == 2) {
clearConsole();
// before the program go to the
// menu, the program will check
// if item has stock
if (Burger_Sandwich_Stock[0] == 0 &&
Burger_Sandwich_Stock[1] == 0 &&
Burger_Sandwich_Stock[2] == 0 &&
Burger_Sandwich_Stock[3] == 0 &&
Burger_Sandwich_Stock[4] == 0) {
// if the item has no
// stock, set the
// soldout to true and
// the program will go
// to the menu
Soldout[0] = true;
Menu();
} else {
Menu();
}
// if the user enter 0, the
// program will go to the
// Checkout method
} else if (add == 0) {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Thank you Please wait while we process your order |");
System.out.println(
"+---------------------------------------------------+");
int random = (int) (Math
.random() *
(100 - 2000 + 1)) +
2000;
Thread.sleep(random);
Order_List();
// if the user enter a number
// that is not 0, 1 or 2,
// the program will display the
// error message and go back to
// the Category 1
} else {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| You can only enter either [1],[2] or [0] |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
Category(choice);
}
}
}
// if the user enter more than the number of the item,
// the program will display the error message and go
// back to the Category 1
} else {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Sorry, the item you selected is Not Available |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
Category(1);
}
}
}
break;
case 2:
if (Meals_Stock[0] == 0 && Meals_Stock[1] == 0 && Meals_Stock[2] == 0 &&
Meals_Stock[3] == 0 && Meals_Stock[4] == 0) {
Soldout[1] = true;
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| This item is sold out |");
System.out.println(
"+---------------------------------------------------+\n");
System.out.print("Do you want to add more items? (Y/N): ");
String add = breader.readLine();
if (add.equalsIgnoreCase("Y")) {
clearConsole();
Menu();
} else if (add.equalsIgnoreCase("N")) {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Thank you Please wait while we process your order |");
System.out.println(
"+---------------------------------------------------+");
// Random delay between 0.1 to 2 seconds
int random = (int) (Math.random() * (2000 - 100 + 1) + 100);
Thread.sleep(random);
Order_List();
} else {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| You can only enter Y or N |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
Category(choice);
}
} else {
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Meals |");
System.out.println(
"+---------------------------------------------------+\n");
System.out.println(String.format(format, "", "Item", "", "Qty", "Price",
""));
System.out.println(
"-----------------------------------------------------");
for (int i = 0; i < Meals.length; i++) {
if (Meals_Stock[i] == 0) {
System.out.println(String.format(format, "[" + (i + 1) +
"] ", Meals[i], "-", "Out of Stock", "",
""));
} else if (Meals_Price[i] == 0.0) {
System.out.println(String.format(format, "[" + (i + 1) +
"] ", Meals[i], "-", Meals_Stock[i],
"Free", ""));
} else {
System.out.println(String.format(format, "[" + (i + 1) +
"] ", Meals[i], "-", Meals_Stock[i],
Meals_Price[i], "Php"));
}
}
System.out.println(String.format(format, "", "", "", "", "------------",
""));
System.out.println(String.format(format, "", "", "", "", "[0] Back",
""));
System.out.println(
"_____________________________________________________");
System.out.print("Enter your choice: ");
int M_choice = Integer.parseInt(breader.readLine());
int index = M_choice - 1;
int M_quantity = 0;
if (M_choice == 0) {
clearConsole();
Menu();
} else {
if (M_choice <= Meals.length) {
if (Meals_Stock[index] == 0) {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Sorry, the item you selected is Out of Stock |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
Category(2);
} else {
clearConsole();
System.out.println(
"----------------- You have selected -----------------");
System.out.println(String.format(format, "",
"Item", "", "Qty", "Price",
""));
System.out.println(
"-----------------------------------------------------");
System.out.println(String.format(format, "",
Meals[index], "",
Meals_Stock[index],
Meals_Price[index], "Php"));
System.out.println(
"-----------------------------------------------------");
System.out.print(
"Enter the quantity you want to buy: ");
M_quantity = Integer.parseInt(breader
.readLine());
if (M_quantity > Meals_Stock[index]) {
clearConsole();
System.out.println(
"-----------------------------------------------------");
System.out.println(
"Sorry, we only have [" +
Meals_Stock[index] +
"] " +
Meals[index] +
" in stock");
System.out.println(
"-----------------------------------------------------");
Thread.sleep(2000);
clearConsole();
Category(2);
} else {
clearConsole();
System.out.println(
"-----------------------------------------------------");
System.out.println("You ordered [" +
M_quantity + "] " +
Meals[index] + "\n");
Meals_Choice[index]++;
Meals_Stock[index] -= M_quantity;
Meals_Order[index] += M_quantity;
Check_for_Order[1] = true;
System.out.println(
"-----------------------------------------------------");
System.out.print(
"[1] Add more items\n[2] Choose a different category\n[0] Checkout\n");
System.out.println(
"_____________________________________________________");
System.out.print("Enter your choice: ");
int add = Integer.parseInt(breader
.readLine());
if (add == 1) {
clearConsole();
Category(2);
} else if (add == 2) {
clearConsole();
if (Meals_Stock[0] == 0 &&
Meals_Stock[1] == 0 &&
Meals_Stock[2] == 0 &&
Meals_Stock[3] == 0 &&
Meals_Stock[4] == 0) {
Soldout[1] = true;
Menu();
} else {
Menu();
}
} else if (add == 0) {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Thank you Please wait while we process your order |");
System.out.println(
"+---------------------------------------------------+");
int random = (int) (Math
.random() *
(100 - 2000 + 1)) +
2000;
Thread.sleep(random);
Order_List();
} else {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| You can only enter either [1],[2] or [0] |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
Category(choice);
}
}
}
} else {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Sorry, the item you selected is Not Available |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
Category(2);
}
}
}
break;
case 3:
if (Drinks_Stock[0] == 0 && Drinks_Stock[1] == 0 && Drinks_Stock[2] == 0 &&
Drinks_Stock[3] == 0 && Drinks_Stock[4] == 0 &&
Drinks_Stock[5] == 0) {
Soldout[2] = true;
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| This item is sold out |");
System.out.println(
"+---------------------------------------------------+\n");
System.out.print("Do you want to add more items? (Y/N): ");
String add = breader.readLine();
if (add.equalsIgnoreCase("Y")) {
clearConsole();
Menu();
} else if (add.equalsIgnoreCase("N")) {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Thank you Please wait while we process your order |");
System.out.println(
"+---------------------------------------------------+");
// Random delay between 0.1 to 2 seconds
int random = (int) (Math.random() * (2000 - 100 + 1) + 100);
Thread.sleep(random);
Order_List();
} else {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| You can only enter Y or N |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
Category(choice);
}
} else {
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Drinks |");
System.out.println(
"+---------------------------------------------------+\n");
System.out.println(String.format(format, "", "Item", "", "Qty", "Price",
""));
System.out.println(
"-----------------------------------------------------");
for (int i = 0; i < Drinks.length; i++) {
if (Drinks_Stock[i] == 0) {
// if the stock is 0, the item is sold out and print out
// the out of stock message
System.out.println(String.format(format, "[" + (i + 1) +
"] ", Drinks[i], "-", "Out of Stock",
"", ""));
} else if (Drinks_Price[i] == 0.0) {
// If the price is 0.0, the item is free and print out
// the free message
System.out.println(String.format(format, "[" + (i + 1) +
"] ", Drinks[i], "-", Drinks_Stock[i],
"Free", ""));
} else {
// if the stock is not 0, and or the price is not 0.0,
// print out the item
System.out.println(String.format(format, "[" + (i + 1) +
"] ", Drinks[i], "-", Drinks_Stock[i],
Drinks_Price[i], "Php"));
}
}
System.out.println(String.format(format, "", "", "", "", "------------",
""));
System.out.println(String.format(format, "", "", "", "", "[0] Back",
""));
System.out.println(
"_____________________________________________________");
System.out.print("Enter your choice: ");
int Ds_choice = Integer.parseInt(breader.readLine());
int index = Ds_choice - 1;
int Ds_quantity = 0;
if (Ds_choice == 0) {
clearConsole();
Menu();
} else {
if (Ds_choice <= Drinks.length) {
if (Drinks_Stock[index] == 0) {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Sorry, the item you selected is Out of Stock |");
System.out.println(
"+---------------------------------------------------+");
Thread.sleep(3000);
clearConsole();
Category(3);
} else {
clearConsole();
System.out.println(
"----------------- You have selected -----------------");
System.out.println(String.format(format, "",
"Item", "", "Qty", "Price",
""));
System.out.println(
"-----------------------------------------------------");
System.out.println(String.format(format, "",
Drinks[index], "",
Drinks_Stock[index],
Drinks_Price[index], "Php"));
System.out.println(
"-----------------------------------------------------");
System.out.print(
"Enter the quantity you want to buy: ");
Ds_quantity = Integer.parseInt(breader
.readLine());
if (Ds_quantity > Drinks_Stock[index]) {
clearConsole();
System.out.println(
"-----------------------------------------------------");
System.out.println(
"Sorry, we only have [" +
Drinks_Stock[index] +
"] " +
Drinks[index] +
" in stock");
System.out.println(
"-----------------------------------------------------");
Thread.sleep(2000);
clearConsole();
Category(3);
} else {
clearConsole();
System.out.println(
"-----------------------------------------------------");
System.out.println("You ordered [" +
Ds_quantity + "] " +
Drinks[index] + "\n");
Drinks_Choice[index]++;
Drinks_Stock[index] -= Ds_quantity;
Drinks_Order[index] += Ds_quantity;
Check_for_Order[2] = true;
System.out.println(
"-----------------------------------------------------");
System.out.print(
"[1] Add more items\n[2] Choose a different category\n[0] Checkout\n");
System.out.println(
"_____________________________________________________");
System.out.print("Enter your choice: ");
int add = Integer.parseInt(breader
.readLine());
if (add == 1) {
clearConsole();
Category(3);
} else if (add == 2) {
clearConsole();
if (Drinks_Stock[0] == 0 &&
Drinks_Stock[1] == 0 &&
Drinks_Stock[2] == 0 &&
Drinks_Stock[3] == 0 &&
Drinks_Stock[4] == 0 &&
Drinks_Stock[5] == 0) {
Soldout[2] = true;
Menu();
} else {
Menu();
}
} else if (add == 0) {
clearConsole();
System.out.println(
"+---------------------------------------------------+");
System.out.println(
"| Thank you Please wait while we process your order |");
System.out.println(
"+---------------------------------------------------+");
int random = (int) (Math
.random() *
(100 - 2000 + 1)) +
2000;
Thread.sleep(random);