34.6k views
4 votes
A Chinese restaurant has two types of dinner combos for customers to choose. A regular dinner combo includes main dish and soup. A deluxe dinner combo includes main dish, soup and appetizer. There are three main dish choices: sweet and sour pork ($7), sesame chicken ($8) or shrimp fried rice ($9). There are two soup choices: egg drop soup ($1.25) or wanton soup ($1.50). There are two appetizer choices: spring roll ($1.25) or chicken wing ($1.50). They need a program to place orders. You Python project needs to follow these requirements:

(a) Create a Dinner_combo class for regular dinner combos. This class has three protected instance variables: main_dish, soup and total. Define a choose_dish method to choose a main dish, a choose_soup method to choose a soup, and a displayOrder method to display items ordered and total amount due.

(b) Create a Deluxe_dinner_combo class for deluxe dinner combos. This class is a derived class of the dinner_combo class. It has one additional protected instance variables: appetizer. Define a choose_appetizer method to choose an appetizer, and a displayOrder method to display items ordered and total amount due.

(c) In the main module, ask user to choose either regular or deluxe dinner combo. Create an object and call its methods to input food items and display information of the order.

1 Answer

1 vote

Answer:

class Dinner_combo:

def __init__(self):

self._main_dish = ''

self._soup = ''

self._total = 0#these are all protected classes

def choose_dish(self):

print('Type a number to select Main Dish:\\1. sweet and sour pork\\2. sesame chicken\\3. shrimp fried rice ')

userInput = input('Enter Main Dish Number:')

print()

amount = 0

if userInput == '1':

self._main_dish = 'sweet and sour pork'

amount = amount + 7

elif userInput == '2':

self._main_dish = 'sesame chicken'

amount = amount + 8

elif userInput =='3':

self._main_dish = 'shrimp fried rice'

amount = amount + 9

return self._main_dish, amount

def choose_soup(self):

print('Type a number to select Soup:\\1. egg drop\\2. wanton ')

userInput = input('Enter Soup Number:')

print()

amount = 0

if userInput == '1':

self._soup = 'egg drop'

amount = amount + 1.25

elif userInput == '2':

self._soup = 'wanton'

amount = amount + 1.50

return self._soup, amount

def displayOrder(self):

mainDish = list(self.choose_dish())

soup = list(self.choose_soup())

self._total = mainDish[1] + soup[1]

message = '\\\\your Order\\\\Main Dish - {} ${}\\Soup - {} ${}\\\\TOTAL = ${}'.format(mainDish[0],mainDish[1], soup[0], soup[1], self._total)

return message

pass

class Deluxe_dinner_combo(Dinner_combo):

def __init__(self):

super().__init__()

self._appetizer = ''

def choose_appetizer(self):

print('Type a number to select Appetizer:\\1. spring roll\\2. chicken wing ')

userInput = input('Enter Appetizer Number:')

print()

amount = 0

if userInput == '1':

self._appetizer = 'spring roll'

amount = amount + 1.25

elif userInput == '2':

self._appetizer = 'chicken wing'

amount = amount + 1.50

return self._appetizer, amount

def displayOrder(self):

mainDish = list(self.choose_dish())

soup = list(self.choose_soup())

appetizer = list(self.choose_appetizer())

self._total = mainDish[1] + soup[1] +appetizer[1]

message = '\\\\your Order\\\\Main Dish - {} ${}\\Soup - {} ${}\\Appeizer - {} ${}\\\\TOTAL = ${}'.format(mainDish[0],mainDish[1], soup[0], soup[1], appetizer[0], appetizer[1],self._total)

return message

if __name__ == '__main__':

print('-----WELCOME------\\\\Please Select a Dinner Plan\\Type a number to select:\\1. Dinner Combo\\2. Deluxe Dinner Combo')

dinner = input('Enter Number Here:')

print()

if dinner == '1':

customer = Dinner_combo()

elif dinner == '2':

customer = Deluxe_dinner_combo()

print(customer.displayOrder())

Step-by-step explanation:

The programming language used is python 3.

There are three parts to this code, the supper class, the child class and the main class.

The Supper Class (Dinner_combo):

The supper class is defined and it contains its three protected instances, two methods are created to select the main dish and the soup, and a third to display the customer order, the displayOrder function calls the other functions within itself and sums up the amount and prints the order list and the result.

The sub-class (Deluxe_dinner_combo):

This class inherits all the protected instances and the methods from its parent class and has another extra appetizer instance and choose_appetizer method.

the displayOrder in this subclass overrides the one in the parent class, it also includes the appetizer to its order list.

Main Module:

The user is prompted to select a dinner plan and depending on the dinner plan selected, a customer object is created and the necessary meals are called from within their methods and displayOrder method returns the items ordered, their price and the total amount.

I have attached a picture for you to see how it works.

A Chinese restaurant has two types of dinner combos for customers to choose. A regular-example-1
User Charlee Chitsuk
by
5.6k points