Here is my task: Create classes for a menu plan. With the help of the classes it should be possible to create a menu card for a restaurant in a hotel.
There should be a 'MenuCard' class for this purpose. This should include a date for the card and one or more course menus. Use an appropriate data type in Python for the date. It should be possible to add the courses to a menu card one after the other with a method add_course. There should be a class 'Course' for the course menu. This has a name (e.g. starter or first course). Furthermore, each course has one or more dishes, which can be added with the 'add_dish' method. For this purpose, the 'Dish' class is to be assembled, which is the name of the food administration and whether it is vegetarian. Use the str function in all classes to display the menu card on the screen.
Additional task: Create a class for a three-course menu ThreeCourseMenuCard, which the existing class sequences. With this class you have to make sure that there are no more than (or exactly) three courses.
Create your own personal map by controlling instances from the classes.
I already programmed this, but its to complicated for some users i know. Can someone give me any ideas on how to simplify this program. Thank you in advance.
Here is my code:
#! /usr/bin/python3
import datetime, locale
class Dish():
def __init__(self, name, veggy):
self.__name = name
self.__veggy = veggy
def __str__(self):
if self.__veggy == bool(1):
return "{} (vegetarisch)".format(self.__name)
else:
return "{}".format(self.__name)
class Course():
def __init__(self, name):
self.__name = name
def add_dish(self):
for i in range(len(self.__name[1])):
print(Dish(self.__name[1][i][0], self.__name[1][i][1]))
if i < len(self.__name[1])-1:
print("oder")
def __str__(self):
return "\n\n{}\n".format(self.__name[0][0])
class MenuCard():
def __init__(self, date):
self.__date = date.strftime('%A, %d.%m.%Y')
def add_course(self, new_course):
print(Course(new_course))
Course(new_course).add_dish()
def __str__(self):
return "\n\nMenukarte fuer {}".format(self.__date)
vorspeise = [["Vorspeise"],[
["Carpaggio vom Rind auf knackigem Blattsalat", 0],
["Honigmelone mit hausgemachtem Speck vom Hängebauchschwein", 0]
]]
suppe = [["Suppe"],[
["Kräftige Rindssuppe mit Eiertörtchen", 1]
]]
erster_gang = [["1. Gang"],[
["Salat vom Buffet", 0]
]]
zweiter_gang = [["2. Gang"],[
["Wiener Schnitzel mit Kartoffelsalat", 0],
["Wildsaibling an Herbstgemüse auf Safranrisotto", 0],
["Saftiges Hirschgulasch mit Kastanienrotkraut und Semmelknödel", 0],
["Spinatlasagne mit frischen Tomaten", 1]
]]
nachspeise = [["Nachspeise"],[
["Vanilleparfait auf Himbeerspiegel", 1],
["Luftige Topfenknödel mit roter Grütze", 0]
]]
locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
menu = MenuCard(datetime.datetime(2020, 11, 9))
print(menu)
gaenge = [vorspeise, suppe, erster_gang, zweiter_gang, nachspeise]
for gang in gaenge:
menu.add_course(gang)
```