-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.java
173 lines (137 loc) · 3.77 KB
/
Menu.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
import java.util.ArrayList;
import java.util.List;
import java.util.*;
abstract class MenuItem {
private String id;
private String name;
private int price;
public MenuItem(String id, String name, int price) {
this.id = id;
this.name = name;
this.price = price;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public abstract String getType();
}
class Dish extends MenuItem {
private String cuisineType;
public Dish(String id, String name, int price, String cuisineType) {
super(id, name, price);
this.cuisineType = cuisineType;
}
public String getCuisineType() {
return cuisineType;
}
public void setCuisineType(String cuisineType) {
this.cuisineType = cuisineType;
}
@Override
public String getType() {
return "Dish";
}
}
class Drink extends MenuItem {
private String isAlcoholic;
public Drink(String id, String name, int price, String isAlcoholic) {
super(id, name, price);
this.isAlcoholic = isAlcoholic;
}
public String getIsAlcoholic() {
return isAlcoholic;
}
public void setIsAlcoholic(String isAlcoholic) {
this.isAlcoholic = isAlcoholic;
}
@Override
public String getType() {
return "Drink";
}
}
class Menu {
private List<MenuItem> menus;
public Menu() {
this.menus = new ArrayList<>();
}
public void addMenu(MenuItem menu) {
menus.add(menu);
}
public void removeItem(String id) {
menus.removeIf(menus -> menus.getId().equals(id));
}
public void displayItems() {
for (MenuItem menu : menus) {
System.out.println("ID: " + menu.getId() + " Name: " + menu.getName() + " Price: " + menu.getPrice());
if (menus instanceof Dish) {
System.out.println("Dish: " + ((Dish) menus).getCuisineType());
} else if (menus instanceof Drink) {
System.out.println("Drink: " + ((Drink) menus).getIsAlcoholic());
}
}
}
public static void main(String[] args) {
Menu menu = new Menu();
Scanner s = new Scanner(System.in);
while(true) {
System.out.println("Restaurant Management System");
System.out.println("1. ADD DISH");
System.out.println("2. ADD DRINK");
System.out.println("3. REMOVE ITEM");
System.out.println("4. DISPLAY ITEM");
System.out.println("5. EXIT");
int decis = Integer.parseInt(s.nextLine());
switch(decis) {
case 1:
System.out.println("Enter Dish ID: ");
String dishId = s.nextLine();
System.out.println("Enter Dish Name: ");
String dishName = s.nextLine();
System.out.println("Enter Dish Price: ");
int dishPrice = s.nextInt();
System.out.println("Enter Cuisine Type: ");
String csType = s.nextLine();
menu.addMenu(new Dish (dishId, dishName, dishPrice, csType));
break;
case 2:
System.out.println("Enter Drink ID: ");
String drinkId = s.nextLine();
System.out.println("Enter Drink Name: ");
String drinkName = s.nextLine();
System.out.println("Enter Drink Price: ");
int drinkPrice = s.nextInt();
System.out.println("Is the Drink Alcoholic?: ");
String isAlco = s.nextLine();
menu.addMenu(new Drink (drinkId, drinkName, drinkPrice, isAlco));
break;
case 3:
System.out.println("Enter ID to Remove: ");
String removeId = s.nextLine();
menu.removeItem(removeId);
break;
case 4:
menu.displayItems();
break;
default:
System.out.println("BYE BYE");
s.close();
return;
}
}
}
}