Question
Complete in Python In this second part of the lab you will add on to your Class. In addition to the number of patties a
Complete in Python
In this second part of the lab you will add on to your Class. In addition to the number of patties a user can choose for their burger, they can also choose extra toppings. A typical burger comes with tomato, onion and pickles. Cheese, bacon, onion straws, grilled onions and grilled mushrooms are extra. These extra costs are as follows: Cheese = $0.75, Bacon = $1.00, Grilled Onions = $0.50 and Grilled Mushrooms = $0.50.
Add to your class a method to determine the cost of the extras. This method will need to ask the user what type of topping they want. The user can choose multiple toppings (HINT: there needs to be a loop here). The method will then use this choice to determine an extras cost. That value needs to be added or summed with the other extras choices.
Also add to your class a method that will determine the total cost of the burger. This total will be based on the base cost as determined in the first part of the lab and the extras cost.
Finally include in your class methods that allow the extras cost and the total cost to leave the class.
Back in main() print out the extras cost and the total cost.
code from part one-
class BurgerCost: #Constructor def __init__(self, singleprice, doubleprice): self.single_price = singleprice self.double_price = doubleprice #Calculation Methods def cost(self, patty_type, number_of_patty): if patty_type.upper() == "S": return self.single_price * number_of_patty elif patty_type.upper() == "D": return self.double_price * number_of_patty #Access Methods def get_signle_price(self): return self.single_price def get_double_price(selfs): return selfs.double_price
def main(): #declare variables userburgertype = str() #ask user for the type of burger userburgertype = input("Enter S for a single patty burger or D for a double patty burger: ") #creating the MyBurger object MyBurger = BurgerCost(5.95 ,7.95) print("Here is the cost of your burger:") print("\tBurger Cost:\t$", MyBurger.cost(userburgertype)) main()
Code from part 2-
class BurgerCost: #Copy and paste code from part 1 here
def determineExtraCost(self): #ask user for their extras print("Enter your extras:") print("\tC = Cheese") print("\tB = Bacon") print("\tO = Grilled Onions") print("\tM = Grilled Mushrooms") print("\tQ = Quit") self.__extratype = input() #finish the rest
def main(): #declare variables userburgertype = str()
#ask user for the type of burger userburgertype = input("Enter S for a single patty burger or D for a double patty burger: ") #display burger costs to the user print("Here is the cost of your burger:") print("\tBurger Cost:\t$", #finish this print("\tExtra Costs:\t$", #finish this print("\t\t\t---------") print("\tTotal Cost:\t$", #finish this print()
Output should look like this
Enter S for a single patty burger or D for a double patty burger: S Enter your extras: C = Cheese B = Bacon O = Grilled Onions M = Grilled Mushrooms Q = Quit C Enter your extras: C = Cheese B = Bacon O = Grilled Onions M = Grilled Mushrooms Q = Quit B Enter your extras: C = Cheese B = Bacon O = Grilled Onions M = Grilled Mushrooms Q = Quit Q Here is the cost of your burger: Burger Cost: $ 5.95 Extra Costs: $ 1.75 --------- Total Cost: $ 7.701 class BurgerCost: 2 Copy and paste code from part 1 here 5 def determineExtracost self) ask user for their extras print ("Enter your extras: print ltC Cheese print ("VtB Bacon") print ("Vto Grilled onions" prin ("V Grilled Mushrooms tM 11 print ("Vt Quit") self extratype input 14 #finish the rest 15 17 18 def main() declare variables 20 userburgertype str() main.py Load default template
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started