Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following classes represent Food items at Pollock Dining Commons that students put in their food Tray during breakfast, lunch or dinner. Examples of functionality

The following classes represent Food items at Pollock Dining Commons that students put in their food Tray during breakfast, lunch or dinner. Examples of functionality are provided in the docstring. class Food: """ name -> str price_per_unit -> int/float >>> food_item_1 = Food('Donut', 1.5) >>> food_item_2 = Food('Scrambled Eggs', 2) >>> food_item_1.cost() 1.5 >>> food_item_2.cost() 2 """ def __init__(self, name, price_per_unit): self.name = name self.price_per_unit = price_per_unit def cost(self): return self.price_per_unit class Tray: """ >>> food_item_1 = Food('Donut', 1.5) >>> food_item_2 = Food('Scrambled Eggs', 2) >>> my_breakfast = Tray() >>> my_breakfast.add_to_tray(food_item_1) >>> my_breakfast.add_to_tray(food_item_2) >>> my_breakfast.add_to_tray(food_item_1) >>> my_breakfast.add_to_tray(food_item_1) >>> my_breakfast.items [, , , ] >>> my_breakfast Tray contents: Donut, Scrambled Eggs, Donut, Donut """ def __init__(self): self.items = [] def add_to_tray(self, food_item): self.items.append(food_item) def __str__(self): str_repr = [] for food_item in self.items: str_repr.append(food_item.name) return 'Tray contents: ' + ', '.join(str_repr) __repr__ = __str__ You are asked to write classes that extend the Food class, so we can represent the various food categories available: Main dishes, Snack, and Drink (we will consider drinks as a special type of food). We will also have a special case for Hot Drinks as they require special cups that cost more. While for the most part, these items will behave exactly like the generic Food items, there are some unique properties. Snacks should be classified under either sweet or savory, by an additional parameter that is used to initialize them. Main dishes should be initialized with an extra parameter is_seasonal which will be either True or False. If its a seasonal dish, the cost should be equal to 0.85*price_per_unit. Hot drinks should have a class variable HOT_CUP_PRICE and have the cost equal to the price of the drink plus this price. Finally, implement a Plate class. A Plate is separate from a Tray, and stores at most one food and one drink item. If you try to add more, you will get an error message. Some sample functionality is provided below: >>> new_plate = Plate() >>> soda = Drink("Pepsi", 2) >>> snack = Snack("Pretzel", 3) >>> new_plate.add_item(soda) Added successfully. >>> new_plate.add_item(snack) Added successfully. >>> new_plate.add_item(soda) This plate already has a drink. Assume that all these classes are written such that they appropriately use the design principles discussed in Module 3.2 (inheritance and polymorphism). Remember that inheritance allows the subclass to use the same blueprint of the parent class just by including the parent class name in the subclass definition. Do not repeat unnecessary code that is already available. Assume that the initialization method of a Food item was accidentally modified in a way that causes an error whenever it is run. Instances of which classes could successfully be created despite this mistake? Main Food Plate HotDrink Drink Snack

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions