w3resource

Python Class - Restaurant Management System


2. Restaurant Class with Menu, Table Reservation, and Order Management

Write a Python class Restaurant with attributes like menu_items, book_table, and customer_orders, and methods like add_item_to_menu, book_tables, and customer_order.

Perform the following tasks now:

  • Now add items to the menu.
  • Make table reservations.
  • Take customer orders.
  • Print the menu.
  • Print table reservations.
  • Print customer orders.
Note: Use dictionaries and lists to store the data.

Sample Solution:

Python Code:

class Restaurant:
    def __init__(self):
        self.menu_items = {}
        self.book_table = []
        self.customer_orders = []

    def add_item_to_menu(self, item, price):
        self.menu_items[item] = price

    def book_tables(self, table_number):
        self.book_table.append(table_number)

    def customer_order(self, table_number, order):
        order_details = {'table_number': table_number, 'order': order}
        self.customer_orders.append(order_details)

    def print_menu_items(self):
        for item, price in self.menu_items.items():
            print("{}: {}".format(item, price))

    def print_table_reservations(self):
        for table in self.book_table:
            print("Table {}".format(table))

    def print_customer_orders(self):
        for order in self.customer_orders:
            print("Table {}: {}".format(order['table_number'], order['order']))

restaurant = Restaurant()

# Add items
restaurant.add_item_to_menu("Cheeseburger", 9.99)
restaurant.add_item_to_menu("Caesar Salad", 8)
restaurant.add_item_to_menu("Grilled Salmon", 19.99)
restaurant.add_item_to_menu("French Fries", 3.99)
restaurant.add_item_to_menu("Fish & Chips:", 15)
# Book table
restaurant.book_tables(1)
restaurant.book_tables(2)
restaurant.book_tables(3)
# Order items
restaurant.customer_order(1, "Cheeseburger")
restaurant.customer_order(1, "Grilled Salmon")
restaurant.customer_order(2, "Fish & Chips")
restaurant.customer_order(2, "Grilled Salmon")

print("\nPopular dishes in the restaurant along with their prices:")
restaurant.print_menu_items()
print("\nTable reserved in the Restaurant:")
restaurant.print_table_reservations()
print("\nPrint customer orders:")
restaurant.print_customer_orders()

Sample Output:

Popular dishes in the restaurant along with their prices:
Cheeseburger: 9.99
Caesar Salad: 8
Grilled Salmon: 19.99
French Fries: 3.99
Fish & Chips:: 15

Table reserved in the Restaurant:
Table 1
Table 2
Table 3

Print customer orders:
Table 1: Cheeseburger
Table 1: Grilled Salmon
Table 2: Fish & Chips
Table 2: Grilled Salmon

Flowchart:

Flowchart: Restaurant Management System
Flowchart: Restaurant Management System
Flowchart: Restaurant Management System

For more Practice: Solve these Related Problems:

  • Write a Python class Restaurant that includes methods for adding, updating, and removing menu items, and also handles table cancellation and waitlisting.
  • Write a Python class Restaurant that maintains a log of customer orders, calculates the total revenue, and prints a detailed sales report.
  • Write a Python class Restaurant with a dynamic menu that allows seasonal updates and includes a method to display a sorted menu by item price.
  • Write a Python class Restaurant that incorporates customer feedback by storing ratings for each order and then calculates the average rating for each menu item.

Go to:


Previous: Employee Management System.
Next: Restaurant Management System.

Python Code Editor:

Contribute your code and comments through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.