-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathBurger Application in java
388 lines (288 loc) · 7.59 KB
/
Burger Application in 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
class DeluxeBurger extends Hamburger{
private int potatop=10,coldp=10;
public DeluxeBurger(String bread, String meat, int price) {
super(bread, meat, price, "Deluxe Burger");
super.setTotp(super.getTotprice()+potatop+coldp);
}
@Override
public void Additions() {
super.Additions();
System.out.println("Potato Chips :"+potatop);
System.out.println("Cold Drink :"+coldp);
}
@Override
public int getBasePrice() {
// TODO Auto-generated method stub
return super.getBasePrice();
}
@Override
public int getTotprice() {
return super.getTotprice();
}
}
public class Hamburger {
private String bread,meat,name;
int e1,e2,e3,e4,e5,e6;
private int price,totp;
private int tomatop=2, onionp=1,mayop=3,cheesep=5,lettucep=4,cornp=4;
void setE5(int e5)
{
this.e5 = e5;
}
void setE6(int e6)
{
this.e6 = e6;
}
void setTotp(int tot)
{
this.totp=tot;
}
public Hamburger(String bread, String meat, int price, String name) {
super();
this.bread = bread;
this.meat = meat;
this.price = price;
this.name = name;
this.totp=price;
}
public int getBasePrice() {
return price;
}
public void Additions()
{
System.out.println("***********************************************************************************************************");
System.out.println(" BILL's Burgers ");
System.out.println("Add On's you opted for :");
if(e1==1||e2==1||e3==1||e4==1||e5==1||e6==1) {
System.out.println("Tomatoes: $"+tomatop);
totp+=tomatop;
}
if(e1==2||e2==2||e3==2||e4==2||e5==2||e6==2) {
System.out.println("Onions: $"+onionp);
totp+=onionp;
}
if(e1==6||e2==6||e3==6||e4==6||e5==6||e6==6) {
System.out.println("Mayo: $"+mayop);
totp+=mayop;
}
if(e1==5||e2==5||e3==5||e4==5||e5==5||e6==5) {
System.out.println("Cheese: $"+cheesep);
totp+=cheesep;
}
if(e1==3||e2==3||e3==3||e4==3||e5==1||e6==3) {
System.out.println("Lettuce: $"+lettucep);
totp+=lettucep;
}
if(e1==4||e2==4||e3==4||e4==4||e5==4||e6==4) {
System.out.println("Corn: $"+cornp);
totp+=cornp;
}
if(e1==0 ) {
System.out.println("No additional toppings selected ");
}
}
public int getTotprice() {
return totp;
}
public void setE(int arr) {
this.e1 = arr;
}
public void setE(int arr,int arr2) {
this.setE(arr);
this.e2 = arr2;
}
public void setE(int arr,int arr2,int arr3) {
this.setE(arr,arr2);
this.e3 = arr3;
}
public void setE(int arr,int arr2,int arr3,int arr4) {
this.setE(arr,arr2,arr3);
this.e4 = arr4;
}
/*public void setE(int arr,int arr2,int arr3,int arr4, int arr5)
{
System.out.println("Cannot take more than 4 add ons");
}
public void setE(int arr,int arr2,int arr3,int arr4, int arr5, int arr6)
{
System.out.println("Cannot take more than 4 add ons");
}*/
public void setE(int i, int j, int k, int l, int m) {
// TODO Auto-generated method stub
}
public void setE(int i, int j, int k, int l, int m, int n) {
// TODO Auto-generated method stub
}
}
class HealthyBurger extends Hamburger {
public HealthyBurger(String meat, int price, String name) {
super("brown rye", meat, price, "Healty Burger");
// TODO Auto-generated constructor stub
}
public void setE(int e1,int e2,int e3,int e4,int e5) {
super.setE(e1, e2, e3, e4);
super.setE5(e5);
}
public void setE(int e1,int e2,int e3,int e4,int e5,int e6) {
setE(e1, e2, e3, e4,e5);
super.setE6(e6);
}
@Override
public int getBasePrice() {
return super.getBasePrice();
}
@Override
public void Additions() {
super.Additions();
}
@Override
public int getTotprice() {
// TODO Auto-generated method stub
return super.getTotprice();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int ch1,ch2,ch3 =0, i = 0; int n;String bread = null,meat = null; int[] arr= new int[6];
Scanner in=new Scanner(System.in);
System.out.println("********************************************************************************************************");
System.out.println("What would you like to have today?\n1.Regular Burger\n2.Healthy Burger\n3.Deluxe Burger");
n=in.nextInt();
while(!(n==1|| n==2||n==3))
{
System.out.println("Please make a correct choice.");
n=in.nextInt();
}
if(n==1|| n==3) {
System.out.println("Choose bread\n1.White\n2.Brown rye");
ch1=in.nextInt();
switch(ch1)
{
case 1:
bread="White";
break;
case 2:
bread="Brown Rye";
break;
default:
while(!(ch1==1|| ch1==2)){
System.out.println("Please make a correct choice.");
ch1=in.nextInt();
}
}
}
System.out.println("Choose your choice of meat\n1.Beef\n2.Chicken\n3.Lamb");
ch2=in.nextInt();
switch(ch2)
{
case 1:
meat="Beef";
break;
case 2:
bread="Chicken";
break;
case 3:
meat="Lamb";
break;
default:
while(!(ch2==1|| ch2==2||ch2==3)){
System.out.println("Please make a correct choice.");
ch2=in.nextInt();
}
}
Hamburger h=null;
switch(n)
{
case 1:
h=new Hamburger(bread,meat,20,"Regular Hamburger");
break;
case 2:
h=new HealthyBurger(meat,20,"Healthy Burger");
break;
case 3:
h =new DeluxeBurger(bread,meat,20);
break;
}
System.out.println("Choice of Add on's:\n1.Tomatoes\n2.Onions\n3.Lettuce\n4.Corn\n5.Cheese\n6.Mayo");
if(n==1||n==3) {
System.out.println("Which all add ons?Choose a maximum of 4.Enter 0 to exit");
for( i=0;i<4;i++)
{
ch3=in.nextInt();
while(ch3<0 || ch3>6)
{
System.out.println("Please make a correct choice.");
ch3=in.nextInt();
}
for(int j=0;j<i;j++) {
while(ch3==arr[j])
{
System.out.println("You have aleady selected this option. "+" Select something different.");
ch3=in.nextInt();
j=0;
}
}
if(ch3==0)
break;
else
arr[i]=ch3;
} }
else
if(n==2)
{System.out.println("Which all add ons?Enter 0 to exit");
for( i=0;i<6;i++)
{
ch3=in.nextInt();
while(ch3<0 || ch3>6)
{
System.out.println("Please make a correct choice.");
ch3=in.nextInt();
}
for(int j=0;j<i;j++) {
while(ch3==arr[j])
{
System.out.println("You have aleady selected this option. "+" Select something different.");
ch3=in.nextInt();
j=0;
}
}
if(ch3==0)
break;
else
arr[i]=ch3;
}
}
else
System.out.println("Invalid Choice!");
switch(i)
{
case 0:
break;
case 1:
h.setE(arr[0]);
break;
case 2:
h.setE(arr[0], arr[1]);
break;
case 3:
h.setE(arr[0], arr[1],arr[2]);
break;
case 4:
h.setE(arr[0],arr[1], arr[2], arr[3]);
break;
case 5:
h.setE(arr[0],arr[1], arr[2], arr[3], arr[4]);
break;
case 6:
h.setE(arr[0],arr[1], arr[2], arr[3],arr[4],arr[5]);
break;
}
h.Additions();
System.out.println();
System.out.println();
System.out.println("Please pay $"+h.getTotprice());
System.out.println();
System.out.println("Do visit again!");
}
}