Question
Can you please help me with Python Code? Thanks a lot Here is what I already have: class DessertItem: tax_rate = 0.075 def __init__(self, name,
Can you please help me with Python Code? Thanks a lot
Here is what I already have:
class DessertItem:
tax_rate = 0.075
def __init__(self, name, price):
self.name = name
self.price = price
def __str__(self):
return f"{self.name} @ {self.price:.2f}"
def __eq__(self, other):
return self.price == other.price
def __ne__(self, other):
return self.price != other.price
def __lt__(self, other):
return self.price
def __gt__(self, other):
return self.price > other.price
def __le__(self, other):
return self.price
def __ge__(self, other):
return self.price >= other.price
class Candy(DessertItem):
def __init__(self, weight, price_per_pound):
super().__init__("Gummy Bears (Bag)", price_per_pound)
self.weight = weight
def get_cost(self):
return self.weight * self.price
def __str__(self):
return f"{self.name} ({self.weight} lbs.) @ {self.price:.2f}/lb."
class Cookie(DessertItem):
def __init__(self, cookie_type, quantity, price_per_dozen):
self.type = cookie_type
self.quantity = quantity
super().__init__(f"{cookie_type} Cookies (Box)", price_per_dozen/12)
def get_cost(self):
return self.quantity * self.price
def __str__(self):
return f"{self.name} {self.quantity} cookies @ {self.price*12:.2f}/dozen : ${self.get_cost():.2f}"
class IceCream(DessertItem):
def __init__(self, scoops, price_per_scoop):
super().__init__("Pistachio Ice Cream (Bowl)", price_per_scoop)
self.scoops = scoops
def get_cost(self):
return self.scoops * self.price
def __str__(self):
return f"{self.name} {self.scoops} scoops @ {self.price:.2f}/scoop: ${self.get_cost():.2f}"
class Sundae(DessertItem):
def __init__(self, scoops, flavor, price_per_scoop, topping, topping_price):
super().__init__(f"{flavor} Sundae (Boat)", price_per_scoop)
self.scoops = scoops
self.topping = topping
self.topping_price = topping_price
def get_cost(self):
return self.scoops * self.price + self.topping_price
def __str__(self):
return f"{self.name} {self.scoops} scoops of {self.name.split()[0].lower()} ice cream ${self.price:.2f}/scoop {self.topping} topping @ ${self.topping_price:.2f}: ${self.get_cost():.2f}"
class Order:
def __init__(self):
self.items = []
def add_item(self, item):
self.items.append(item)
def get_total_cost(self):
subtotal = sum(item.get_cost() for item in self.items)
tax = subtotal * DessertItem.tax_rate
return subtotal + tax
def __str__(self):
sorted_items = sorted(self.items)
receipt = "----------------------Receipt:----------------------------- "
for item in sorted_items:
receipt += f"{str(item)} "
receipt += f" Subtotal: ${self.get_total_cost():.2f} "
receipt += f"Tax: ${self.get_total_cost() - sum(item.get_cost() for item in self.items):.2f} "
receipt += f"Total: ${self.get_total_cost():.2f}"
return receipt
# create an order object
order = Order()
# add some items to the order
order.add_item(Candy(0.5, 4.99))
order.add_item(Cookie("Chocolate Chip", 2, 5.99))
order.add_item(IceCream(2, 3.50))
order.add_item(Sundae(3, "Vanilla", 2.75, "Hot Fudge", 1.50))
# print the receipt
print(order)
1. Dessert Shop Part 10: Customer Class Problem Add the ability to keep track of customers and what they have ordered. In this part of the project, you will define a Customer class. In Parts 8 and 9y you were introduced to Python 3 type hints. They are used at program creation time, but ignored at run time-except for protocols-which you may have read in the slides, the Python docs or articles on typing. Part 10 continues adding type hints using Python 3 notation. While not strictly required to pass Part 10, you may want to begin adding your own type hints to your code starting with Part 10. You should not necessarily go back and add type hints to all of your previous code, but if you do, don't let it be a stumbling block. Customer Class The Customer Class has the following attributes and methods: - attribute customer_name: str: - attribute order_history: List[Order] - attribute customer_id: int - a constructor that takes the customer's name as its only parameter. Initialize all other object attributes to reasonable values. - method add2history(order:order)-> add the order to the history and return the Customer object Add this Customer class to the dessertshop module. - Add a yeso loop so that the program asks the user if they want to start another order as soon as the current order is complete and printed. The user should enter " y " and then press "Enter" for yes, and anything else is no. Test Cases Add tests to test the Customer class. You do not need to create a test for the reading the order history. Add these tests to the file Example Scenario Nothing new to show for this part of the project yet. Grading The most you can earn is 50% if all items do not pass
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