-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRestaurants.java
112 lines (90 loc) · 2.49 KB
/
Restaurants.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
package Solutions;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
interface Food {
public String prepareFood();
public double foodPrice();
}
class VegFood implements Food {
public String prepareFood() {
return "Veg Food";
}
public double foodPrice() {
return 50.0;
}
}
abstract class FoodDecorator implements Food {
private Food newFood;
public FoodDecorator(Food newFood) {
this.newFood = newFood;
}
@Override
public String prepareFood() {
return newFood.prepareFood();
}
public double foodPrice() {
return newFood.foodPrice();
}
}
class NonVegFood extends FoodDecorator {
public NonVegFood(Food newFood) {
super(newFood);
}
public String prepareFood() {
return super.prepareFood() + " With Roasted Chiken and Chiken Curry ";
}
public double foodPrice() {
return super.foodPrice() + 150.0;
}
}
class ChineeseFood extends FoodDecorator {
public ChineeseFood(Food newFood) {
super(newFood);
}
public String prepareFood() {
return super.prepareFood() + " With Fried Rice and Manchurian ";
}
public double foodPrice() {
return super.foodPrice() + 65.0;
}
}
public class Restaurants {
private static int choice;
public static void main(String args[]) throws NumberFormatException, IOException {
do {
System.out.print("========= Food Menu ============ \n");
System.out.print(" 1. Vegetarian Food. \n");
System.out.print(" 2. Non-Vegetarian Food.\n");
System.out.print(" 3. Chineese Food. \n");
System.out.print(" 4. Exit \n");
System.out.print("Enter your choice: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
choice = Integer.parseInt(br.readLine());
switch (choice) {
case 1: {
VegFood vf = new VegFood();
System.out.println(vf.prepareFood());
System.out.println(vf.foodPrice());
}
break;
case 2: {
Food f1 = new NonVegFood((Food) new VegFood());
System.out.println(f1.prepareFood());
System.out.println(f1.foodPrice());
}
break;
case 3: {
Food f2 = new ChineeseFood((Food) new VegFood());
System.out.println(f2.prepareFood());
System.out.println(f2.foodPrice());
}
break;
default: {
System.out.println("Other than these no food available");
}
return;
}// end of switch
} while (choice != 4);
}
}