-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPromoSetPack.java
More file actions
221 lines (207 loc) · 6.29 KB
/
Copy pathPromoSetPack.java
File metadata and controls
221 lines (207 loc) · 6.29 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
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
import java.util.Scanner;
import java.util.ArrayList;
/**
* Represents the Promotional Set Package on the menu in a restaurant.
* @author Tan Zheng Kai
* @version 2.0
* @since 2021-11-13
*/
public class PromoSetPack extends MenuItem {
/**
* The list of promotional items in this Promotional set package.
*/
private ArrayList<MenuItem> promo;
/**
* The description of this promotional set package.
*/
private String description;
/**
* The name of this promotional set package.
*/
private String name;
/**
* The price of this promotional set package.
*/
private double price;
/**
* Creates a new promotional set package.
*/
public PromoSetPack(){
this.Type = type.PROMO;
this.promo = new ArrayList< >();
}
/**
* Creates a new promotional set package with given name.
* @param description The description of this promotional set package.
* @param name The name of this promotional set package.
* @param price The price of this promotional set package.
*/
public PromoSetPack(String description, String name, double price){
this.Type = type.PROMO;
this.description = description;
this.name = name;
this.price = price;
this.promo = new ArrayList<MenuItem>();
}
/**
* Update the attributes of the Promotional Set Package.
*/
public void update() {
Scanner sc = new Scanner(System.in); // maybe can implement a while loop
System.out.println("What would you like to update?");
System.out.println("1. Description 2. name 3. price 4. add items to Package 5. delete items from package");
int choice = sc.nextInt();
sc.nextLine();
switch(choice){
case 1:
System.out.println("What is the new description?");
this.description = sc.nextLine();
break;
case 2:
System.out.println("What is the new name?");
this.name = sc.nextLine();
break;
case 3:
System.out.println("What is the new price?");
this.price = sc.nextDouble();
break;
case 4:
addPromoItem();
break;
case 5:
if (this.promo.isEmpty()){
System.out.println("error");
return;
}
this.print();
System.out.println("Which item would you like to delete?");
int promoIndex = sc.nextInt();
sc.nextLine();
this.promo.remove(promoIndex - 1); //delete the index - 1 promoItem from promoPackage
break;
}
System.out.println("Promo Set Package updated, printing updated item...");
this.print();
}
/**
* Prints out the attributes of the promotional set package.
*/
public void print(){
int ListLength = this.promo.size();
System.out.println("Type: "+this.Type);
System.out.println("Name: "+this.name);
System.out.println("Description: "+this.description);
System.out.printf("$%.2f\n", this.price);
System.out.println("Featured dishes:");
for (int i =0; i<ListLength; i++){
System.out.print("\t"+(i+1) + ". ");
System.out.println(this.promo.get(i).getName()); //print name of ala-carte item in promo array
}
System.out.println();
}
/**
* Adds a promotional set item into the promotional item list.
*/
public void addPromoItem(){
Scanner sc = new Scanner(System.in);
try {
int i = 0;
System.out.println();
System.out.println("----------------------------------------------");
while (RestaurantApp.globalMenuManager.getSizeOfMenu()!=i && RestaurantApp.globalMenuManager.getMenuItem(i).Type != type.PROMO){
System.out.println((i+1)+". ");
RestaurantApp.globalMenuManager.getMenuItem(i).print();
System.out.println("----------------------------------------------");
i++;
}
//RestaurantApp.globalMenuManager.printMenu(); //create a globalmenuManager so that other classes can access the menu
System.out.println("Which item would you like to add?");
int menuIndex = sc.nextInt();
sc.nextLine();
if(menuIndex <= 0 || menuIndex >i){
throw new ArrayIndexOutOfBoundsException("Please input a valid index from 1 to "+i);
}
this.promo.add(RestaurantApp.globalMenuManager.getMenuItem(menuIndex-1)); //add the index - 1 menuItem to promoPackage
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
System.out.println("program exiting...");
System.exit(0);
}
}
/**
* A new promotional set package is made through asking for each attribute.
*/
public void createPromo() {
Scanner sc = new Scanner(System.in);
System.out.println("Whats the new promo's name?");
this.name = sc.nextLine();
System.out.println("Whats the new promo's description?");
this.description = sc.nextLine();
System.out.println("Whats the new promo's price?");
this.price = sc.nextDouble();
int createChoice = 0;
while (createChoice < 2){
System.out.println("What would you like to do?");
System.out.println("1. add items 2. quit");
createChoice = sc.nextInt();
sc.nextLine();
if (createChoice == 1){
this.addPromoItem();
}
}
}
/**
* Gets the type of this promotional set package.
* @return the type of the promotional set package.
*/
public type getType() {
return this.Type;
}
/**
* Changes the type of this promotional set package.
* @param type The type of this promotional set package.
*/
public void setType(type type) {
this.Type = type;
}
/**
* Gets the name of this promotional set package.
*/
public String getName() {
return this.name;
}
/**
* Changes the name of this promotional set package.
* @param name The name of this promotional set package.
*/
public void setName(String name) {
this.name = name;
}
/**
* Get the name of this promotional set package.
* @return this promotional set package's name.
*/
public String getDescription() {
return this.description;
}
/**
* Changes the name of this promotional set package.
* @param description The description of this promotional set package.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Gets the price of this promotional set package.
*/
public double getPrice() {
return this.price;
}
/**
* Changes the price of this promotional set package.
* @param price this price of the promotional set package.
*/
public void setPrice(double price) {
this.price = price;
}
}