-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperations.java
349 lines (312 loc) · 11.4 KB
/
Operations.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
import java.security.interfaces.RSAKey;
import java.util.ArrayList;
import java.util.List;
public class Operations {
int giveId[] = new int[100000];
int Rescount = 0;
List<Restaurant> restaurantlList = new ArrayList<>();
List<String> CATEGORY_LIST = new ArrayList<>(); // list of all categories of all restaurants
List<Food> food_items = new ArrayList<>(); // contain all food items of all restaurants
public void setRestaurants(List<Restaurant> restaurants) {
restaurantlList = restaurants;
}
public List<Restaurant> getRestaurants() {
return restaurantlList;
}
private boolean checkId(int id) {
if (Rescount == 0)
return false;
for (int x : giveId) {
if (x == id) {
return true;
}
}
return false;
}
private boolean checkName(String name) {
for (Restaurant x : restaurantlList) {
if (x.getName().equalsIgnoreCase(name)) {
return true;
}
}
return false;
}
private boolean isSame(String x) {
for (String i : CATEGORY_LIST) {
if (i.equals(x))
return true;
}
return false;
}
private void setCategoryList() {
for (Restaurant x : restaurantlList) {
for (int i = 0; i < x.getCatCounter(); i++) {
if (!isSame(x.getCategory()[i])) {
CATEGORY_LIST.add(x.getCategory()[i]);
}
}
}
}
public void CategoryWiseDisplay() {
setCategoryList();
for (int i = 0; i < CATEGORY_LIST.size(); i++) {
System.out.print(CATEGORY_LIST.get(i) + ": ");
for (Restaurant x : restaurantlList) {
for (int j = 0; j < x.getCatCounter(); j++) {
if (x.getCategory()[j].equals(CATEGORY_LIST.get(i)))
System.out.print("," + x.getName());
}
}
System.out.println();
}
}
public void addRestaurant(int id, String name, double score, String zipCode, String catName[]) {
if (checkId(id)) {
System.out.println("Your given Id is already Registered .Please Enter a new id");
return;
}
giveId[Rescount] = id;
Rescount++;
restaurantlList.add(new Restaurant(id, name, score, zipCode, catName));
}
public void addRestaurant(int id, String name, double score, String price, String zipCode, String catName[]) {
if (checkId(id)) {
System.out.println("Your given Id is already Registered .Please Enter a new id");
return;
}
if (checkName(name)) {
System.out.println("Your given Restaurant name is already Registered .Please Enter a new id");
return;
}
giveId[Rescount] = id;
Rescount++;
restaurantlList.add(new Restaurant(id, name, score, price, zipCode, catName));
}
private boolean isResAvailable(String resname) { // equals
for (Restaurant x : restaurantlList) {
if (x.getName().equals(resname))
return true;
}
return false;
}
private boolean isResAvailable(int id) {
for (Restaurant x : restaurantlList) {
if (x.getId() == id)
return true;
}
return false;
}
public void addFoodToMenu(String resName, String category, String foodname, double price) { // equals
if (!isResAvailable(resName)) {
System.out.println("No such resturant is found .Enter Restaurant Name Correctly");
return;
}
for (Restaurant x : restaurantlList) {
if (x.getName().equals(resName)) {
x.addFood(category, foodname, price);
}
}
}
public void searchRestaurant(String name) { // by name
int flag = 0;
for (Restaurant x : restaurantlList) {
if (x.getName().toLowerCase().contains(name.toLowerCase())) {
x.DisplayRestaurant();
flag++;
}
}
if (flag == 0) {
System.out.println("No such Restaurant found with this name.");
}
}
public void DisplayRestaurants(double a, double b) { // display deatails of the restaurants between score by score
int flag = 0;
for (Restaurant x : restaurantlList) {
if (a <= x.getscore() && b >= x.getscore()) {
flag++;
x.DisplayRestaurant();
System.out.println();
}
}
if (flag == 0)
System.out.println("No such restaurant with this score range");
}
public void searchRestaurantByCat(String name) { // by category
int flag = 0;
for (Restaurant x : restaurantlList) {
for (int i = 0; i < x.getCatCounter(); i++) {
if (x.getCategory()[i].toLowerCase().contains(name.toLowerCase())) {
x.DisplayRestaurant();
flag++;
}
}
}
if (flag == 0)
System.out.println("No such restaurant found with this Category");
}
public void searchRestaurantByprice(String price) { // by price
int flag = 0;
for (Restaurant x : restaurantlList) {
if (x.getPrice().equals(price)) {
flag++;
x.DisplayRestaurant();
}
}
if (flag == 0)
System.out.println("No such restaurant with this price");
}
public void searchRestaurantByZipcode(String zipcode) { // by zip code
int flag = 0;
for (Restaurant x : restaurantlList) {
if (x.getzipCode().contains(zipcode)) {
x.DisplayRestaurant();
flag++;
}
}
if (flag == 0)
System.out.println("No such restaurant with this zipcode");
}
private void MakeFoodItemList() { // make a list of all foods of all restaurants
for (Restaurant x : restaurantlList) {
for (int i = 0; i < x.getAllFoods().size(); i++) {
food_items.add(x.getAllFoods().get(i));
}
}
}
public void searchFoodItems(String name) { // search food item by name
MakeFoodItemList();
int flag = 0;
for (int i = 0; i < food_items.size(); i++) {
if (food_items.get(i).getfoodname().toLowerCase().contains(name.toLowerCase())) {
food_items.get(i).DisplayFoodWithId();
flag++;
}
}
if (flag == 0) {
System.out.println("No such food item with this name");
return;
}
System.out.println();
}
public void SearchfoodInResTaurant(String foodname, String Resname) {
int flag = 0;
int flag1 = 0;
System.out.println("foods are: ");
for (Restaurant x : restaurantlList) {
if (x.getName().toLowerCase().contains(Resname.toLowerCase())) {
flag++;
for (Food f : x.getAllFoods()) {
if (f.getfoodname().toLowerCase().contains(foodname.toLowerCase())) {
flag1++;
f.DisplayFoodWithId();
}
}
}
}
if (flag == 0) {
System.out.println("No restaurant found");
return;
}
if (flag1 == 0) {
System.out.println("No such food item with this name in this restaurant");
}
}
public void DisplayfoodFromCategory(String catname) {
int flag = 0;
for (Food f : food_items) {
if (f.getCategory().toLowerCase().contains(catname.toLowerCase())) {
flag++;
f.DisplayFoodWithId();
}
}
if (flag == 0) {
System.out.println("No such Food with this category");
}
}
public void DisplayfoodFromCategoryInRestaurant(String resName, String foodCat) {
int flag = 0;
for (Restaurant x : restaurantlList) {
if (x.getName().toLowerCase().contains(resName.toLowerCase())) {
for (Food f : x.getAllFoods()) {
if (f.getfoodname().toLowerCase().contains(foodCat.toLowerCase())) {
f.DisplayFoodWithId();
flag++;
}
}
}
}
if (flag == 0) {
System.out.println("No such food with this category in this restaurant");
}
}
public void searchFoodwithPrice(double low, double high) {
for (Restaurant x : restaurantlList) {
for (Food f : x.getAllFoods()) {
if (f.getPrice() >= low && f.getPrice() <= high) {
f.DisplayFoodWithId();
}
}
}
}
public void SearchfoodInResTaurantwithprice(double low, double high, String Resname) {
for (Restaurant x : restaurantlList) {
if (x.getName().toLowerCase().contains(Resname.toLowerCase())) {
for (Food f : x.getAllFoods()) {
if (f.getPrice() >= low && f.getPrice() <= high) {
f.DisplayFoodWithId();
}
}
}
}
}
public double maxCostFoodPrice(Restaurant x) {
double max = 0;
for (Food f : x.getAllFoods()) {
if (f.getPrice() > max)
max = f.getPrice();
}
return max;
}
public void DisplayCostliestItemOnRestaurant(String resname) {
int flag = 0;
for (Restaurant x : restaurantlList) {
if (x.getName().toLowerCase().contains(resname.toLowerCase())) {
double max = maxCostFoodPrice(x);
x.DisplayShortlyRestaurant();
for (Food f : x.getAllFoods()) {
if (f.getPrice() == max) {
f.Displayfood();
flag++;
}
}
}
}
if (flag == 0) {
System.out.println("No such Restauratnt is found");
}
}
public void DisplayAllFoodAllrestaurants() {
for (Restaurant x : restaurantlList) {
x.DisplayRestaurantFoods();
}
}
public void addFoodToMenu(int resId, String category, String foodname, double price) { // by id
if (!isResAvailable(resId)) {
System.out.println("No such resturant is found .enter Restaurant Name Correctly");
return;
}
for (Restaurant x : restaurantlList) {
if (x.getId() == resId) {
x.addFood(category, foodname, price);
}
}
}
public void printRes() { // in console
for (Restaurant x : restaurantlList) {
System.out.print(
x.getId() + "," + x.getName() + "," + x.getscore() + "," + x.getPrice() + "," + x.getzipCode());
x.printCategory();
System.out.println();
}
}
}