3
\$\begingroup\$

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)
```
\$\endgroup\$
4
  • \$\begingroup\$ Which Python version are you using? \$\endgroup\$
    – AMC
    Nov 9, 2020 at 20:46
  • \$\begingroup\$ Python version 3.8 \$\endgroup\$
    – python_oop
    Nov 9, 2020 at 20:48
  • \$\begingroup\$ Can you clarify what you mean by but its to complicated for some users i know ? \$\endgroup\$
    – AMC
    Nov 9, 2020 at 21:26
  • \$\begingroup\$ My friend doesn't understand the code on how it is written. So he asked me if there is another way to solve this (more basic). Like if I can remove those nested lists and solve it on another way. \$\endgroup\$
    – python_oop
    Nov 9, 2020 at 21:29

1 Answer 1

5
\$\begingroup\$

MenuCard should have two variables, courses_list and menu_date. In my opinion, the method add_course should take in a Course object as parameter instead of taking in the name of the course.

def add_course(self, new_course: Course):
    self.__courses_list.append(new_course)

Course should have two variables, name and dishes_list. The add_dish method should take in a Dish object as parameter and append it to the dishes_list. Dish seems alright. You should probably change if self.__veggy == bool(1): to if self.__veggy is True:.

\$\endgroup\$
2
  • \$\begingroup\$ Could you change it in the code and sent it here? \$\endgroup\$
    – python_oop
    Nov 9, 2020 at 20:19
  • 3
    \$\begingroup\$ We can't really do all of your homework for you ;-) \$\endgroup\$ Nov 10, 2020 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.