Question: code the assingment. Assignment Instructions For this assignment, you will be creating classes based on the UML diagram below. One class, the Pizza class, has
code the assingment. Assignment Instructions
For this assignment, you will be creating classes based on the UML diagram below. One class, the Pizza class, has code included in the instructions that you can use.
Pizza Class Code:
class PizzaPurchasable:
sizes Small "Medium", "Large", "XtraLarge"
sauces Tomato "Marinara", "Alfredo", "None"
def initself name, size, sauce, pepperoni, sausage, chicken, bacon, ham, onions,
greenpeppers, bananapeppers, redpeppers, blackolives, greenolives,
pineapple, mushrooms, spinach, fetacheese:
if size not in Pizza.sizes:
raise ValueErrorInvalid Size"
if sauce not in Pizza.sauces:
raise ValueErrorInvalid Sauce"
self.size size
self.sauce sauce
self.pepperoni pepperoni
self.sausage sausage
self.chicken chicken
self.bacon bacon
self.ham ham
self.onions onions
self.greenpeppers greenpeppers
self.bananapeppers bananapeppers
self.redpeppers redpeppers
self.blackolives blackolives
self.greenolives greenolives
self.pineapple pineapple
self.mushrooms mushrooms
self.spinach spinach
self.fetacheese fetacheese
name "Custom size Pizza" if name None else name
superinitname self.calculatecost
def calculatecostself:
cost
if self.size "Small":
cost
elif self.size "Medium":
cost
elif self.size "Large":
cost
elif self.size "XtraLarge":
cost
meats
if self.pepperoni:
meats
if self.sausage:
meats
if self.chicken:
meats
if self.bacon:
meats
if self.ham:
meats
if meats :
cost cost meats
tops
if self.onions:
tops
if self.greenpeppers:
tops
if self.bananapeppers:
tops
if self.redpeppers:
tops
if self.blackolives:
tops
if self.greenolives:
tops
if self.pineapple:
tops
if self.mushrooms:
tops
if self.spinach:
tops
if self.fetacheese:
tops
if tops :
cost cost tops
return cost
Additional Information:
To be able to use the Purchasable class and its subclasses as a key in a dictionary it will be necessary to override the eq and hash methods within that class. The eq method can consider two Purchasables equivalent if they have the same name and the same cost. The hash method can return a hash use Python's hash function of a tuple containing the name and cost of the purchasable.
You should create all of the other classes described in the UML Diagram. Sodas can have two sizes oz and Liter' and can be one of these flavors: 'Coke', 'Sprite', Mt Dew', 'Root Beer', 'Orange', 'Grape'. For calculating the cost of a soda, the base cost for a oz Soda is $ and for a Liter' $ and an additional $ if it's a premium Soda which is one of 'Coke', 'Sprite', or Mt Dew'.
For the PizzaFactory class you can broadly decide the exact toppings for the different pizzas. Each factory method should assign a name to the constructed Pizza object so that it doesn't have the "Custom Size Pizza" name assigned to it
The LineItemIterator class for the Order class should iterate over lines in an order and produce output that looks similar to the following:
x Custom Large Pizza $
x Hawaiian Pizza $
x oz Coke $
Testing Your Assignment:
Include some test code as part of your assignment where you create an order Object and add the following to the order:
Pizza created by using the Builder class
different Pizzas created by calling two of the factory methods in your PizzaFactory class
Sodas created by calling the constructor method for the Soda class
Use the LineItemIterator to iterate over the Order you have created and print out each of the line items in the order.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
