-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab55.java
More file actions
151 lines (108 loc) · 4.38 KB
/
lab55.java
File metadata and controls
151 lines (108 loc) · 4.38 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
package com.mycompany.lab55;
import java.util.Scanner;
public class Lab55 {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
Restaurant myRestaurant = new Restaurant();
operateRestaurant(myRestaurant);
}
public static void printMenu(Menu menu){
Meal[] meals = menu.getMeals();
System.out.printf("%-15s %-15s %-10s %-30s\n", "Meal-Code", "Name", "Price", "Description");
System.out.println("-----------------------------------------------------------------------");
if(meals != null){
for(int i = 0; i < meals.length; i++){
System.out.printf("%-15d %-15s %-10.2f %-30s\n",
meals[i].getCode(),
meals[i].name,
meals[i].price,
meals[i].getDescription());
}
}
}
public static void operateRestaurant(Restaurant r){
boolean exit = false;
while(!exit){
System.out.println("\nWhat to do:");
System.out.println("1. Print menu");
System.out.println("2. Add meal");
System.out.println("3. Remove meal");
System.out.println("4. Modify meal");
System.out.println("5. Print the most expensive meal");
System.out.println("6. Print random meal");
System.out.println("7. Exit");
System.out.print("Enter your choice: ");
int choice = input.nextInt();
switch(choice){
case 1:
printMenu(r.menu);
break;
case 2:
r.menu.addMealToTop();
break;
case 3:
boolean REM = r.menu.removeMeal();
if(REM){
System.out.println("Meal removed succescfully");
}
else{
System.out.println("couldnt find code");
}
break;
case 4:
modifyMeal(r);
break;
case 5:
Meal EXP = r.getMostExpensiveMeal();
if(EXP != null)System.out.println("Meal name:"+EXP.name+"\n Meal price"+EXP.price);
break;
case 6:
r.printRandomMeal();
break;
case 7:
exit = true;
System.out.println("EXIT");
break;
default:
System.out.println("INVALIED , TRY AGAIN");
}
}
}
public static void modifyMeal(Restaurant r){
System.out.println("enter meal to modify");
int CODEMODE = input.nextInt();
Meal[] CUR = r.menu.getMeals();
Meal mod = null;
if(CUR != null){
for(int i=0; i<CUR.length;i++){
if(CUR[i].getCode() == CODEMODE){
mod = CUR[i];
break;
}
}
}
if(mod == null){
System.out.println("couildnt fine");
}
else{
System.out.println("1.Modify price");
System.out.println("2.ADD descreption");
int CHOICE = input.nextInt();
if(CHOICE==1){
System.out.println("enter price");
mod.price = input.nextDouble();
System.out.println("price updated");
}
else if(CHOICE ==2){
input.nextLine();
System.out.println("enter desc");
String newDesc = input.nextLine();
mod.addToDescription(newDesc);
System.out.println("DONE");
}
else{
System.out.println("INVALIED CHOICE");
}
}
}
}