Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with Python question. Q2a. Implement the abstract class - FoodItem. The FoodItem class represents a food item that the school cafe is offering. -

Help with Python question.

image text in transcribed

Q2a. Implement the abstract class - FoodItem. The FoodItem class represents a food item that the school cafe is offering.

- It has the 2 instance variables

*_name(str): a description or name for the food item.

*_cost (float): the cost of the food item.

- Constructor initialises these 2 instance variables: _name and _cost.

- Getter methods for name and cost. Use the property decorater.

- One abstract method, expiryHours which returns the expiry hours of the food item.

- The __str__ method returns a string representation of a FoodItem object, including the name, cost and expiry hours of the FoodItem object, including the name, cost and expiry hours of the FoodItem objects.

This is an example in the suggested format:

Name: Strawberry Pudding Price: $2.00 Expiring in 2 hrs.

Q2b. Write Python class definitions for Sandwich and HotSandwich class.

The Sandwich class is a subclass of FoodItem, and it has:

- One additional instance variable: _fillings (str) describing the main ingredients (such as turkey, ham, cheese etc.) of the sandwich.

- Implement the method expiryHours that returns the standard expiry hours of a sandwich as 2 (hours).

The HotSandwich is a subclass of Sandwich and has additional instance variable _toasted(boolean) that indicate if the bread is toasted.

- The method expiryHours returns expiry hours as 1.5 if this hot sandwich is toasted.

Q2c. Explain and describe what type of overriding you have implemented for expiryHours and __str__ methods in class HotSandwich. What is the OO concept that allows for overriding?

Q2d. Write Python statements to invoke the methods you have defined.

Q2d(i). Create the appropriate FoodItem objects using the information in Table Q2(d) below:

image text in transcribed

Q2d(ii). Print the expiry hours for "Toasted Cheese Sandwich". Based on your understanding, what should be the output?

Demonstrate your understanding of how class hierarchy and association are used to organize information, by constructing the class hierarchy and association according to specification. The class diagram in Figure Q2 shows specifications of the food items sold in a school Table 02(d)

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

Students also viewed these Databases questions