Question: Hello, I have tried to code as the sample, but I have some parts I can't figure out. show the price of each item add
Hello,
I have tried to code as the sample, but I have some parts I can't figure out.
- show the price of each item
- add french fries in the result
- erase 'mac and cheese'
- get the result of "This restaurant had 2 orders today for a total of $14.98 in sales" (price and order numbers can be different)
- use sleep function properly
Here is my code:
--------------------------------------------------------
from time import sleep class Restaurant(object): _instance = None _orders = 2 _total_sales = 3 def __new__(cls, *args, **kwargs): if cls._instance is None: cls._instance = object.__new__(cls, *args, **kwargs) return cls._instance def __str__(self): return f"Orders: {self._orders} Total Sales: {self._total_sales}" def order_food(self, food_type): Food.order_food(food_type) class Cheeseburger: def __init__(self): pass def prepare(self): print("Cheeseburger: Preparing cheeseburger") print("Cheeseburger: grill all-beef patty") print("Cheeseburger: flip patty") print("Cheeseburger: put cheese on patty") print("Cheeseburger: put patty on bun and add toppings") print("Cheeseburger: All done!") sleep(2) def __str__(self): return f"Cheeseburger : 5.99" def price(self): return 5.99 class Pasta: def __init__(self): pass def prepare(self): print("Pasta: boiling water.") print("Pasta: boil water for noodles") print("Pasta: saute onions, garlic and tomatoes for sauce") print("Pasta: put noodles in water") print("Pasta: season the sauce") print("Pasta: plate noodles and add sauce on top") print("Pasta: All done!") sleep(2) def __str__(self): return f"Pasta : 6.99" def price(self): return 7.99 class FrenchFries: def __init__(self): pass def prepare(self): print("Frenchfries: take it our from a freezer") print("Frenchfries: put in a fryer") print("Frenchfries: remove it from the fryer") print("Frenchfries: add seasonings") print("Frenchfries: All done!") sleep(2) def __str__(self): return f"Frenchfries : 2.99" def price(self): return 2.99 class food: @staticmethod def order_food(food_type): if type(food_type) == str: food_type = food_type.lower() if food_type == "cheeseburger": food = Cheeseburger() food.prepare() if food_type == "pasta": food = Pasta() food.prepare() if food_type == "Frenchfries": food = Frenchfries() food.prepare() print(food_type) def __init__(self): print("It is debugging.") def price(self): return 0 def prepare(self): pass def main(): r = Restaurant() food = r.order_food("cheeseburger") if food: print(food) food = r.order_food("pasta") if food: print(food) food = r.order_food("french fries") if food: print(food) food = r.order_food("mac and cheese") # doesn't exist, prints failure message if food: print(food) else: print("Sorry, the restaurant does not make 'mac and cheese'") print(r) # If you did extra credit, it will show number of orders and total sales # Use this test to prove we have a single instance of Restaurant: #r2 = Restaurant() #print(r2) #r3 = Restaurant() #print(r3) if __name__ == "__main__": main() --------------------------------------------------------
Question and sample output:


Now, you need to create the Food class derivatives and the logic for their prepare() methods. AT a minimum, provide two derivative classes, maybe Cheeseburger and Pasta. o . O . O str_(self) This should return a string showing the food type and its price. Example: "Cheeseburger: 5.99" Do not hard-code the values. They should come from the class itself. Hint: what does class _name__ display? price(self) Returns the price of the item. This will be whatever value you think is fair for the item. prepare(self) This method encapsulates the faade algorithm for the specific type of food. Typically, each step would be a completely different method, like boil_water(). However, for this lab, you may simply use a print statement and a sleep() call to emulate these sub- processes. Example: print("Pasta: boiling water.") sleep (2) . o Extra credit: Add a third Food derivative of your choice. Now, create a main() method, or just a module-level block of code within the (_name__ == "_main__") test and make some food! Here is some code that you can use (assuming you made Cheeseburger and Pasta classes): def main(): r = Restaurant() food = r.order_food("cheeseburger") if food: print(food) food = r.order_food ("pasta") if food: print(food) # doesn't exist, prints failure message food = r.order_food ("mac and cheese") if food: print(food) print(r) # If you did extra credit, it will show number of orders and total sales # Use this test to prove we have a single instance of Restaurant: r2 = Restaurant() print(r2) if main": name main() The output generated by this (yours may differ based on the steps each food type takes in your code): Cheeseburger: grill all-beef patty Cheeseburger: flip patty Cheeseburger: put cheese on patty Cheeseburger: put patty on bun and add toppings Cheeseburger: All done! Cheeseburger: 5.99 Pasta: boil water for noodles Pasta: saute onions, garlic and tomatoes for sauce Pasta: put noodles in water Pasta: season the sauce Pasta: plate noodles and add sauce on top Pasta: All done! Pasta: 8.99 Sorry, the restaurant does not make 'mac and cheese' This restaurant had 2 orders today for a total of $14.98 in sales This restaurant had 2 orders today for a total of $14.98 in sales
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
