-
Notifications
You must be signed in to change notification settings - Fork 0
/
pizzaProgram.rb
416 lines (293 loc) · 8.95 KB
/
pizzaProgram.rb
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# Ethan Roberts
# Created Winter 2018
# Pizza Program using Ruby
# This was just another random program created
# to get a feel of Ruby syntax and also learn inheritance
# works in the language.
class Order
def getHowMany
total = 0
print "\nEnter how many you need for this order (if none, enter 0):\n"
total = gets.to_i
end
end
class Cart < Order
def initialize
@orderCounter = 0
@cart = Array.new
end
end
class PizzaOrder < Cart
PIZZAMARGHERITA = "Pizza Margherita"
HAWAIIANPIZZA = "Hawaiian Pizza"
MEATLOVER = "Meat Lovers"
FAMILY = "Family Size"
INDIV = "Individual Size"
SODA = "Soda"
DIET = "Diet Soda"
BEER = "Beer"
CHEESE = "Cheese"
HAM = "Ham"
PEPP = "Pepparoni"
GREENPEPPER = "Green-Pepper"
ONIONS = "Onions"
MUSHROOMS = "Mushrooms"
PINEAPPLE = "Pinapple"
SHIRT = "YLPP Shirt"
MUG = "YLPP Mug"
#Method below is used for pizza selection
def createOrder
@pizzaHash = Hash.new
@pizzaHash[1] = Array.new
@pizzaHash[2] = Array.new
@pizzaHash[3] = Array.new
@pizzaHash[4] = Array.new
@pizzaHash[5] = Array.new
i = 0
entry = 0
pizzaChosen = 0
print "\n\nLet's order pizza..."
numOfPizzas = self.getHowMany #get number of pizzas for order being added
while (i < numOfPizzas)
print"\nEnter number (1-5) pertaining to the kind of pizza you want: \n"
print " 1.) Pizza Margherita (tomato and cheese)\n"
print " 2.) Hawaiian Pizza (tomato, cheese, ham, pineapple)\n"
print " 3.) Meat Lovers (tomato, cheese, ham, pepparoni)\n"
print " 4.) Family Size\n"
print " 5.) Individual Size\n\n\n"
entry = gets.to_i
pizzaChosen = entry
if (entry > 0)
self.assignPizza(entry)
end
i = i + 1
self.getToppings(pizzaChosen) #begin adding toppings
@pizzaHash[pizzaChosen].each do |x|
@cart.push(x)
end
end
self.getDrinks
end
def assignPizza(entry)
if (entry == 1)
@cart.push(PIZZAMARGHERITA)
elsif (entry == 2)
@cart.push(HAWAIIANPIZZA)
elsif (entry == 3)
@cart.push(MEATLOVER)
elsif (entry == 4)
@cart.push(FAMILY)
elsif (entry == 5)
@cart.push(INDIV)
end
end
def getToppings(pizzaChosen)
i = 0
entry = 0
print "\n\nLet's order toppings..."
numOfToppings = self.getHowMany #get number of toppings being added
while (i < numOfToppings)
print"\n\nEnter number (1-6) pertaining to the topping you want: \n"
print " 1.) Cheese\n"
print " 2.) Ham\n"
print " 3.) Pepparoni\n"
print " 4.) Green-Pepper\n"
print " 5.) Onions\n"
print " 6.) Mushrooms\n\n\n"
entry = gets.to_i
if (entry > 0)
self.assignToppings(pizzaChosen,entry)
end
i = i + 1
end
end
def assignToppings(pizzaChosen,entry)
if (entry == 1)
@pizzaHash[pizzaChosen].push(CHEESE)
elsif (entry == 2)
@pizzaHash[pizzaChosen].push(HAM)
elsif (entry == 3)
@pizzaHash[pizzaChosen].push(PEPP)
elsif (entry == 4)
@pizzaHash[pizzaChosen].push(GREENPEPPER)
elsif (entry == 5)
@pizzaHash[pizzaChosen].push(ONIONS)
elsif (entry == 6)
@pizzaHash[pizzaChosen].push(MUSHROOMS)
end
end
def getDrinks
i = 0
entry = 0
print "\n\nOrdering drinks..."
numOfDrinks = self.getHowMany #get number of drinks
while (i < numOfDrinks)
print"\n\nEnter number (1-3) pertaining to the kind of drink you are ordering: \n"
print " 1.) Soda\n"
print " 2.) Diet Soda\n"
print " 3.) Beer\n\n\n"
entry = gets.to_i
if (entry > 0)
self.assignDrink(entry)
end
i = i + 1
end
self.getMerchandise
end
def assignDrink(entry)
if (entry == 1)
@cart.push(SODA)
elsif (entry == 2)
@cart.push(DIET)
elsif (entry == 3)
@cart.push(BEER)
end
end
def getMerchandise
i = 0
entry = 0
print "\n\nOrdering merchandise..."
numOfMerch = self.getHowMany
while (i < numOfMerch)
print"\n\nEnter number (1-2) pertaining to the kind of merchandise you are ordering: \n"
print " 1.) YLPP Shirt\n"
print " 2.) YLPP Mug\n\n\n"
entry = gets.to_i
if (entry > 0)
self.assignMerchandise(entry)
end
i = i + 1
end
end
def assignMerchandise(entry)
if (entry == 1)
@cart.push(SHIRT)
elsif (entry == 2)
@cart.push(MUG)
end
end
def addToppingMenu
print"\nEnter number (1-5) to select pizza you are adding topping to: \n"
print " 1.) Pizza Margherita (tomato and cheese)\n"
print " 2.) Hawaiian Pizza (tomato, cheese, ham, pineapple)\n"
print " 3.) Meat Lovers (tomato, cheese, ham, pepparoni)\n"
print " 4.) Family Size\n"
print " 5.) Individual Size\n\n\n"
entry = gets.to_i
pizzaChosen = entry
print"\nEnter number (1-6) to select topping you are adding: \n"
print " 1.) Cheese\n"
print " 2.) Ham\n"
print " 3.) Pepparoni\n"
print " 4.) Green-Pepper\n"
print " 5.) Onions\n"
print " 6.) Mushrooms\n\n\n"
entry = gets.to_i
toppingChosen = entry
self.addTopping(pizzaChosen,toppingChosen)
end
def addTopping(pizzaChosen,toppingChosen)
if (toppingChosen == 1)
@cart.push(CHEESE)
elsif (toppingChosen == 2)
@cart.push(HAM)
elsif (toppingChosen == 3)
@cart.push(PEPP)
elsif (toppingChosen == 4)
@cart.push(GREENPEPPER)
elsif (toppingChosen == 5)
@cart.push(ONIONS)
elsif (toppingChosen == 6)
@cart.push(MUSHROOMS)
end
end
def removeToppingMenu
print"\nEnter number (1-5) to select pizza you are removing topping from: \n"
print " 1.) Pizza Margherita (tomato and cheese)\n"
print " 2.) Hawaiian Pizza (tomato, cheese, ham, pineapple)\n"
print " 3.) Meat Lovers (tomato, cheese, ham, pepparoni)\n"
print " 4.) Family Size\n"
print " 5.) Individual Size\n\n\n"
entry = gets.to_i
pizzaChosen = entry
print"\nEnter number (1-6) to select topping you are removing: \n"
print " 1.) Cheese\n"
print " 2.) Ham\n"
print " 3.) Pepparoni\n"
print " 4.) Green-Pepper\n"
print " 5.) Onions\n"
print " 6.) Mushrooms\n\n\n"
entry = gets.to_i
toppingChosen = entry
self.removeTopping(pizzaChosen,toppingChosen)
end
def removeTopping(pizzaChosen,toppingChosen)
if (toppingChosen == 1)
@cart.delete(CHEESE)
elsif (toppingChosen == 2)
@cart.delete(HAM)
elsif (toppingChosen == 3)
@cart.delete(PEPP)
elsif (toppingChosen == 4)
@cart.delete(GREENPEPPER)
elsif (toppingChosen == 5)
@cart.delete(ONIONS)
elsif (toppingChosen == 6)
@cart.delete(MUSHROOMS)
end
end
def displayCart
@cart.each do |x|
print x
print " -- "
end
print "\n"
end
end #end class
#--------------------------------------------------------
#--------------------------------------------------------
#Begin driver portion
#--------------------------------------------------------
#--------------------------------------------------------
myOrder = [] # this array will hold orders
orderCounter = 0
decision = 0 #set to one to begin prompt
while (decision < 5) # while user has not finalized order
if (orderCounter > 0) # if greater than 0, this will be the second order
print "\n\n\nPlease select a prompt: \n"
print " 1.) Place another Order\n"
print " 2.) Add Topping\n"
print " 3.) Remove Toppings\n"
print " 4.) View Cart of Current Order\n"
print " 5.) Submit Order\n\n\n"
decision = gets.chomp.to_i
if (decision == 1)
orderCounter = orderCounter + 1
print "\nCreating another order..."
myOrder[orderCounter] = PizzaOrder.new
myOrder[orderCounter].createOrder #begin order
elsif (decision == 2)
myOrder[orderCounter].addToppingMenu #refer to previous order
elsif (decision == 3)
myOrder[orderCounter].removeToppingMenu #refer to previous order
elsif (decision == 4)
print "\nHere is what's in your cart:\n"
myOrder[orderCounter].displayCart # view cart
end
else #order has not been created, create order
print "\n\nCreating order..."
orderCounter = orderCounter + 1
myOrder[orderCounter] = PizzaOrder.new #create object
myOrder[orderCounter].createOrder #begin order
end
end
print "\n\nORDER COMPLETE AND SUBMITTED\n\n"
i = 1
while(i <= orderCounter)
print "Order "
print i
print ": "
myOrder[i].displayCart
i = i + 1
print "\n"
end