-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurant_Ordering_System .java
More file actions
293 lines (214 loc) · 10.5 KB
/
Restaurant_Ordering_System .java
File metadata and controls
293 lines (214 loc) · 10.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
import java.util.*;
class Restaurant_Ordering_System {
static Scanner ip = new Scanner(System.in);
static int orderprice = 0;
static String billItems = "";
public static void main(String[] args) {
System.out.println("\n====================================");
System.out.println(" ONLINE FOOD ORDERING");
System.out.println("====================================");
System.out.print("\nEnter Customer Name : ");
String name = ip.nextLine();
// Mobile validation
String mobile;
while (true) {
System.out.print("Enter Mobile Number : ");
mobile = ip.next();
if (mobile.length() == 10 && mobile.matches("\\d+")) {
break;
} else {
System.out.println("Invalid Mobile Number. Enter exactly 10 digits.");
}
}
// Order type
System.out.println("\nOrder Type");
System.out.println("1. Dine-in");
System.out.println("2. Takeaway");
System.out.print("Select Option : ");
int orderType = ip.nextInt();
int packingCharge = (orderType == 2) ? 30 : 0;
int billID = (int) (Math.random() * 900000) + 100000;
// Restaurant list
System.out.println("\n----------- RESTAURANTS -----------");
System.out.printf("%-10s %-25s\n", "Hotel No", "Restaurant Name");
System.out.println("---------------------------------------");
System.out.printf("%-10d %-25s\n", 1, "Buhari Restaurant");
System.out.printf("%-10d %-25s\n", 2, "Saravana Bhavan");
System.out.printf("%-10d %-25s\n", 3, "Aasife Biriyani");
System.out.print("\nSelect Restaurant : ");
int hotel = ip.nextInt();
boolean more = true;
while (more) {
int price = 0;
String itemName = "";
int itemChoice;
switch (hotel) {
case 1 -> {
System.out.println("\n------ Buhari Restaurant Menu ------");
System.out.printf("%-10s %-20s %-10s\n", "Item No", "Food", "Price");
System.out.println("---------------------------------------------");
System.out.printf("%-10d %-20s ₹%-10d\n", 1, "Chicken Biryani", 220);
System.out.printf("%-10d %-20s ₹%-10d\n", 2, "Mutton Biryani", 320);
System.out.printf("%-10d %-20s ₹%-10d\n", 3, "Chicken 65", 180);
System.out.print("\nSelect Item : ");
itemChoice = ip.nextInt();
switch (itemChoice) {
case 1 -> {
itemName = "Chicken Biryani";
price = 220;
}
case 2 -> {
itemName = "Mutton Biryani";
price = 320;
}
case 3 -> {
itemName = "Chicken 65";
price = 180;
}
default -> {
System.out.println("Invalid Item!");
continue;
}
}
}
case 2 -> {
System.out.println("\n------ Saravana Bhavan Menu ------");
System.out.printf("%-10s %-20s %-10s\n", "Item No", "Food", "Price");
System.out.println("---------------------------------------------");
System.out.printf("%-10d %-20s ₹%-10d\n", 1, "Ghee Roast", 90);
System.out.printf("%-10d %-20s ₹%-10d\n", 2, "Meals", 120);
System.out.printf("%-10d %-20s ₹%-10d\n", 3, "Mini Tiffin", 150);
System.out.print("\nSelect Item : ");
itemChoice = ip.nextInt();
switch (itemChoice) {
case 1 -> {
itemName = "Ghee Roast";
price = 90;
}
case 2 -> {
itemName = "Meals";
price = 120;
}
case 3 -> {
itemName = "Mini Tiffin";
price = 150;
}
default -> {
System.out.println("Invalid Item!");
continue;
}
}
}
case 3 -> {
System.out.println("\n------ Aasife Biriyani Menu ------");
System.out.printf("%-10s %-20s %-10s\n", "Item No", "Food", "Price");
System.out.println("---------------------------------------------");
System.out.printf("%-10d %-20s ₹%-10d\n", 1, "Egg Biryani", 160);
System.out.printf("%-10d %-20s ₹%-10d\n", 2, "Tandoori Full", 450);
System.out.printf("%-10d %-20s ₹%-10d\n", 3, "Garlic Naan", 45);
System.out.print("\nSelect Item : ");
itemChoice = ip.nextInt();
switch (itemChoice) {
case 1 -> {
itemName = "Egg Biryani";
price = 160;
}
case 2 -> {
itemName = "Tandoori Full";
price = 450;
}
case 3 -> {
itemName = "Garlic Naan";
price = 45;
}
default -> {
System.out.println("Invalid Item!");
continue;
}
}
}
default -> {
System.out.println("Invalid Restaurant!");
return;
}
}
// NEW LINE ADDED
System.out.println("\nOrder Placed : " + itemName + "\n");
System.out.print("Enter Quantity : ");
int qty = ip.nextInt();
int total = price * qty;
orderprice += total;
billItems += String.format("%-15s x%d*%-5d ₹%-5d\n", itemName, qty, price, total);
System.out.print("\nAdd More Items? (1:Yes / 2:No) : ");
if (ip.nextInt() != 1)
more = false;
}
// Calculations
double discount = (orderprice > 500) ? orderprice * 0.10 : 0;
double gst = (orderprice - discount) * 0.05;
double finalTotal = orderprice - discount + gst + packingCharge;
// Bill
System.out.println("\n====================================");
System.out.println(" FINAL BILL");
System.out.println("====================================");
System.out.println("Customer : " + name);
System.out.println("Mobile : " + mobile);
System.out.println("Type : " + (orderType == 1 ? "Dine-in" : "Takeaway"));
System.out.println("------------------------------------");
System.out.printf("%-15s %-12s %-8s\n", "Item Name", "Qty*Price", "Total");
System.out.println("------------------------------------");
System.out.print(billItems);
System.out.println("------------------------------------");
System.out.printf("Subtotal : ₹%d\n", orderprice);
if (discount > 0)
System.out.printf("Discount (10%%) : -₹%.2f\n", discount);
System.out.printf("GST (5%%) : ₹%.2f\n", gst);
if (packingCharge > 0)
System.out.printf("Packing Charge : ₹%d\n", packingCharge);
System.out.println("------------------------------------");
System.out.printf("GRAND TOTAL : ₹%.2f\n", finalTotal);
System.out.println("------------------------------------");
// Payment
System.out.println("\nSelect Payment Method");
System.out.println("1. UPI / GPay");
System.out.println("2. Cash");
System.out.print("\nEnter Option : ");
int payment = ip.nextInt();
try {
if (payment == 1) {
System.out.println("\n[SYSTEM] Connecting to Payment Gateway...");
Thread.sleep(1500);
System.out.print("Enter Bill ID (" + billID + ") : ");
int confirm = ip.nextInt();
if (confirm == billID) {
System.out.print("Verifying Payment");
for (int i = 0; i < 3; i++) {
Thread.sleep(800);
System.out.print(".");
}
int orderID = (int) (Math.random() * 10000);
System.out.println("\n\nPayment Successful!");
System.out.println("Order ID : ORD" + orderID);
System.out.println("Status : Sent to Kitchen");
} else {
System.out.println("\nVerification Failed.");
}
} else {
int orderID = (int) (Math.random() * 10000);
System.out.println("\nOrder Registered!\n");
System.out.println("Order ID : ORD" + orderID + "\n");
System.out.println("Please pay ₹" + (int) finalTotal + " at counter.");
System.out.println("\n------------------------------------");
System.out.println("(: Please proceed to the Cashier Counter");
System.out.println(" Show Order ID: ORD" + orderID);
System.out.println(" Pay ₹" + (int) finalTotal + " to confirm your order :)");
System.out.println("------------------------------------");
}
System.out.println("\n====================================");
System.out.println("THANKS " + name.toUpperCase() + " VISIT AGAIN!");
System.out.println("====================================\n");
} catch (InterruptedException e) {
System.out.println("System Error.");
}
}
}