Repository navigation
Expand file tree
/
Copy pathFoodOrderingSystem.java
More file actions
546 lines (467 loc) · 17.7 KB
/
Copy pathFoodOrderingSystem.java
File metadata and controls
546 lines (467 loc) · 17.7 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
import java.util.*;
import java.io.*;
public class FoodOrderingSystem {
static Scanner scanner = new Scanner(System.in);
static void CheckInput() {
clearScreen(); // Clear the screen
System.out.print("\n\t\tPress 1 to Pay " + calculateSum(TotalBill) + ".\n\t\tPress 2 to Cancel Payment.\n");
int cpay = scanner.nextInt();
switch (cpay) {
case 1:
System.out.print("\n\t\t-) Your payment of " + calculateSum(TotalBill) + " rupees is received successfully.\n");
// ps("Pay.mp3");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("\n\t\t Thank You For Visiting INDIAN FOOD TRUCK.");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// ps("Thanking.mp3");
clearScreen();
System.exit(0);
break;
case 2:
System.out.print("Payment Cancellation of " + calculateSum(TotalBill) + " rupees is successful.\n");
try {
Thread.sleep(800);
} catch (InterruptedException e) {
e.printStackTrace();
}
DeleteOrderItems();
DeleteItemsCart();
System.exit(0);
break;
default:
System.out.println("Enter Valid input.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
CheckInput();
break;
}
}
static void CheckCVVNo() {
// clearScreen(); // Clear the screen
System.out.print("\n\t\tEnter CVV number (in 3 digits): ");
int cvv = scanner.nextInt();
String checkCvv = Integer.toString(cvv);
if (checkCvv.length() == 3) {
CheckInput();
} else {
System.out.println("\t\t\tInvalid CVV number.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
deleteLastTwoLines();
CheckCVVNo();
}
}
static void CheckCardNo() {
clearScreen(); // Clear the screen
System.out.println();
System.out.println("\n\t\t---Enter Card Details---");
System.out.print("\t\tEnter your Card number (in 12 digits): ");
long cno = scanner.nextLong();
String checkCno = Long.toString(cno);
if (checkCno.length() == 12) {
CheckCVVNo();
} else {
System.out.println("\t\t\tInvalid Card number.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
deleteLastFourLines();
CheckCardNo();
}
}
static void PayBill() {
clearScreen(); // Clear the screen
System.out.print("\n\t\t >>> Bill of your Order is " + calculateSum(TotalBill) + ".\n");
System.out.println("\n\t\t>> Press 1 to pay via card.");
System.out.println("\t\t>> Press 2 to pay via UPI.");
System.out.println("\t\t>> Press 3 for Cancel Payment and Exit.");
int payment_option = scanner.nextInt();
switch (payment_option) {
case 1:
// clearScreen();
CheckCardNo();
break;
case 2:
clearScreen();
System.out.println("\n\t\tThe UPI ID is 1234567897.");
System.out.print("\n\t\t-) Payment of " + calculateSum(TotalBill) + " is received.\n");
System.out.println("\n\t\t Thank You For Visiting INDIAN FOOD TRUCK.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
clearScreen();
System.exit(0);
break;
case 3:
System.out.printf("Payment Cancellation of %d rupees is successful.\n", calculateSum(TotalBill));
System.exit(0);
break;
default:
System.out.println("Enter Correct Choice.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
PayBill();
break;
}
}
static int calculateSum(ArrayList<Integer> list) {
int sum = 0;
for (int num : list) {
sum += num;
}
return sum;
}
static void DisplayCart() {
clearScreen(); // Clear the screen
try (BufferedReader br = new BufferedReader(new FileReader("Display Cart.txt"))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.print("\n\t\t Bill of your Order is " + calculateSum(TotalBill) + ".\n");
System.out.println("\n\n\tPress 1 to Pay Bill.");
System.out.println("\tPress 2 to Order More Items.");
System.out.println("\tPress 3 to Cancel Order and order again.");
System.out.println("\tPress 4 to exit.");
int display_bill = scanner.nextInt();
switch (display_bill) {
case 1:
DeleteOrderItems();
DeleteItemsCart();
PayBill();
break;
case 2:
MenuPage();
break;
case 3:
TotalBill.clear();
DeleteOrderItems();
DeleteItemsCart();
MenuPage();
break;
case 4:
DeleteOrderItems();
DeleteItemsCart();
clearScreen();
System.exit(0);
break;
default:
System.out.println("Enter Valid input.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
DisplayCart();
break;
}
}
static void ReOrderLogic() {
System.out.println("\t\t\t");
int re_order = scanner.nextInt();
try {
if (re_order == 1) {
DisplayCart();
} else if (re_order == 2) {
MenuPage();
} else if (re_order == 3) {
TotalBill.clear();
DeleteOrderItems();
DeleteItemsCart();
MenuPage();
} else if (re_order == 4) {
DeleteOrderItems();
DeleteItemsCart();
clearScreen();
System.exit(0);
} else {
System.out.print("\t\t\t- " + re_order + " is an incorrect option.\n\t\t\t- ReEnter Your Choice.\n");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
deleteLastThreeLines();
ReOrderLogic();
}
} catch (Exception e) {
System.out.printf("\t\t\t- %d is an invalid input.\n\t\t\t- ReEnter Your Choice.\n", re_order);
deleteLastThreeLines();
ReOrderLogic();
}
}
static void displayOrderedItems() {
clearScreen(); // Clear the screen
try (BufferedReader br = new BufferedReader(new FileReader("Display Ordered Items.txt"))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static final ArrayList<Integer> TotalBill = new ArrayList<>();
static void addToCart() {
try (FileWriter writer = new FileWriter("Display Cart.txt", true)) {
writer.write(String.format("\n\t\t - %s %s of Price :- %d.", Quantity, FoodItem, FinalPrice));
} catch (IOException e) {
e.printStackTrace();
}
}
static void storeOrderedData() {
try (FileWriter writer = new FileWriter("Display Ordered Items.txt", true)) {
writer.write(
String.format("\n\t- You have selected %s %s of price :- %d", Quantity, Name_Of_Food, FinalPrice));
} catch (IOException e) {
e.printStackTrace();
}
}
static void DeleteItemsCart() {
clearScreen(); // Clear the screen
try (BufferedReader br = new BufferedReader(new FileReader("Display Cart.txt"))) {
String firstLine = br.readLine(); // Read the first line
try (FileWriter writer = new FileWriter("Display Cart.txt")) {
if (firstLine != null) {
writer.write(firstLine); // Write the first line back to the file
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void DeleteOrderItems() {
try (FileWriter writer = new FileWriter("Display Ordered Items.txt")) {
writer.write(""); // Clear the contents of the file
} catch (IOException e) {
e.printStackTrace();
}
}
static int Quantity;
static int FinalPrice;
public static void quantity() {
System.out.print("\t\t || Enter the Quantity of " + Name_Of_Food + " you would like to have : ");
Quantity = scanner.nextInt();
try {
if (Quantity <= 0) {
System.out.println("\t\t\t - Enter Quantity Greater than ZERO.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
deleteLastTwoLines();
quantity();
} else {
deleteLastTwoLines();
FinalPrice = Price * Quantity;
storeOrderedData();
addToCart();
TotalBill.add(FinalPrice); // Assuming TotalBill is a list
}
} catch (NumberFormatException e) {
System.out.print("\t\t\t- " + Quantity + " is an invalid input, ReEnter Your Choice.\n");
deleteLastTwoLines();
quantity();
}
}
static String Name_Of_Food;
static int Price;
static String FoodItem;
public static void StoreNameOrderedItem() {
try (BufferedReader br = new BufferedReader(new FileReader("Menu_for_order_logic.txt"))) {
String line;
while ((line = br.readLine()) != null) {
if (line.contains(String.valueOf(foodId))) {
String[] parts = line.split(":-");
String with3 = parts[0].trim();
Name_Of_Food = with3.substring(3);
Price = Integer.parseInt(parts[1].trim());
FoodItem = Name_Of_Food;
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean foodIdCheck(int foodId) {
try (BufferedReader br = new BufferedReader(new FileReader("Id_Check.txt"))) {
String line;
while ((line = br.readLine()) != null) {
if (line.equals(String.valueOf(foodId))) {
return true;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
public static void ReOrder() {
System.out.println("\n\t\t>> Press 1 to Display Cart.");
System.out.println("\t\t>> Press 2 to Order More Items.");
System.out.println("\t\t>> Press 3 to Cancel Order and Order Again.");
System.out.println("\t\t>> Press 4 to Exit.");
ReOrderLogic();
}
public static void DisplayOrderedItems() {
try (BufferedReader br = new BufferedReader(new FileReader("Display Ordered Items.txt"))) {
clearScreen(); // Clear the screen
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
static int foodId;
// static int i;
public static void itemOrder(int i) {
System.out.print("\t\t || Enter the ID of " + i + " item that you would like to Order : ");
foodId = scanner.nextInt();
if (foodId == '\n') {
System.out.printf("\t\t\t - %d is an Invalid Choice.\n\t\t\t - ReEnter Your Choice.\n", foodId);
scanner.nextLine(); // Clear input buffer
deleteLastThreeLines();
itemOrder(i);
} else if (foodIdCheck(foodId)) {
StoreNameOrderedItem();
quantity();
} else {
System.out.print("\t\t\t - Food ID " + foodId + " is not available.\n\t\t\t - ReEnter the ID of Food.\n");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
scanner.nextLine(); // Clear input buffer
deleteLastThreeLines();
itemOrder(i);
}
}
public static void deleteLastLines() {
for (int i = 0; i < 1; i++) {
System.out.print("\033[1A"); // Move cursor up one line
System.out.print("\033[2K"); // Clear the line
}
}
public static void deleteLastTwoLines() {
for (int i = 0; i < 2; i++) {
System.out.print("\033[1A"); // Move cursor up one line
System.out.print("\033[2K"); // Clear the line
}
}
public static void deleteLastThreeLines() {
for (int i = 0; i < 3; i++) {
System.out.print("\033[1A"); // Move cursor up one line
System.out.print("\033[2K"); // Clear the line
}
}
public static void deleteLastFourLines() {
for (int i = 0; i < 4; i++) {
System.out.print("\033[1A"); // Move cursor up one line
System.out.print("\033[2K"); // Clear the line
}
}
static int ItemOrder;
public static void Order() {
System.out.print("\t >> How many items would you like to order in total : ");
ItemOrder = scanner.nextInt();
if (ItemOrder > 0) {
for (int i = 1; i <= ItemOrder; i++) {
itemOrder(i);
}
DisplayOrderedItems();
ReOrder();
} else {
System.out.println("\t\t\t- Enter Items Greater than ZERO.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
scanner.nextLine(); // Clear input buffer
deleteLastTwoLines();
Order();
}
}
public static void Menu() {
try (BufferedReader br = new BufferedReader(new FileReader("Menu.txt"))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void MenuPage() {
clearScreen();
Menu();
Order();
}
public static void clearScreen() {
System.out.print("\033[H\033[2J");
System.out.flush();
}
public static void Custinput() {
Scanner sc = new Scanner(System.in);
try (BufferedReader br = new BufferedReader(new FileReader("Welcome Page.txt"))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
int CustomerInput = sc.nextInt();
if (CustomerInput == 1) {
MenuPage();
} else {
System.out.println("\n\t\t- " + CustomerInput + " is Not a Valid Input.\n\t\t- Enter Your Choice Again.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Clear input buffer
sc.nextLine();
clearScreen();
Custinput(); // Recursive call
}
sc.close();
}
public static void main(String args[]) {
DeleteOrderItems();
DeleteItemsCart();
Custinput();
}
}