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.