-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFood_Delivery_System.py
More file actions
154 lines (133 loc) · 5.52 KB
/
Food_Delivery_System.py
File metadata and controls
154 lines (133 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
class Restaurant:
# List to keep track of all restaurants
restaurants = []
def __init__(self, name, menu):
"""
Initializes the Restaurant with a name and a menu.
The menu is a dictionary with item names as keys and prices as values.
"""
self.name = name
self.menu = menu
Restaurant.restaurants.append(self)
@classmethod
def show_restaurants(cls):
"""Displays all available restaurants."""
if not cls.restaurants:
print("No restaurants available yet.")
return None
print("\nAvailable Restaurants:")
for idx, restaurant in enumerate(cls.restaurants, start=1):
print(f"{idx}. {restaurant.name}")
return cls.restaurants
def show_menu(self):
"""Displays the menu of the restaurant."""
print(f"\nMenu for {self.name}:")
for idx, (item, price) in enumerate(self.menu.items(), start=1):
print(f"{idx}. {item} - ${price}")
class Order:
order_count = 0
def __init__(self, restaurant, items):
"""
Initializes an order with a restaurant and a list of ordered items.
"""
Order.order_count += 1
self.order_id = Order.order_count
self.restaurant = restaurant
self.items = items
self.status = "Preparing" # Initial status
def track_order(self):
"""Displays the status of the order."""
print(f"Order #{self.order_id} from {self.restaurant.name}: Status - {self.status}")
# def update_status(self, status):
# """Updates the status of the order."""
# self.status = status
# print(f"Order #{self.order_id} status updated to {self.status}")
class Customer:
def __init__(self, name):
self.name = name
self.cart = {}
self.orders = []
def browse_restaurants(self):
"""Lets the customer browse through available restaurants."""
restaurants = Restaurant.show_restaurants()
if restaurants:
res_choice = int(input("\nSelect a restaurant (number): ")) - 1
if 0 <= res_choice < len(restaurants):
restaurant = restaurants[res_choice]
restaurant.show_menu()
self.add_to_cart(restaurant)
else:
print("Invalid restaurant selection!")
def add_to_cart(self, restaurant):
"""Adds items to the cart."""
while True:
item = input("\nEnter item to add (or type 'done' to finish): ").strip()
if item.lower() == 'done':
break
if item in restaurant.menu:
quantity = int(input(f"Enter quantity for {item}: "))
if restaurant not in self.cart:
self.cart[restaurant] = {}
self.cart[restaurant][item] = self.cart[restaurant].get(item, 0) + quantity
else:
print("Item not available in this restaurant's menu.")
def view_cart(self):
"""Displays items in the cart."""
if not self.cart:
print("\nCart is empty.")
return
print("\nYour Cart:")
for restaurant, items in self.cart.items():
print(f"\nRestaurant: {restaurant.name}")
for item, qty in items.items():
print(f"{item} - Quantity: {qty}")
def place_order(self):
"""Places the order."""
if not self.cart:
print("\nCart is empty. Please add items first!")
return
for restaurant, items in self.cart.items():
order = Order(restaurant, items)
self.orders.append(order)
print("\nOrder placed successfully!")
self.cart.clear() # Clear the cart after placing the order
def track_orders(self):
"""Tracks and displays all orders."""
if not self.orders:
print("\nNo orders placed yet.")
return
print("\nYour Orders:")
for order in self.orders:
order.track_order()
class FoodDeliverySystem:
def __init__(self):
self.customers = []
def start(self):
"""Starts the food delivery system."""
print("Welcome to the Food Delivery System!")
# Create some sample restaurants and their menus
Restaurant("Dominos", {"Onion": 8.99, "Golden Corn": 9.99, "FarmHouse": 10.99})
Restaurant("McDonalds", {"Cheese Burger": 6.99, "Veggie Burger": 5.99, "Double Cheese Burger": 7.99})
customer_name = input("Enter your name: ")
customer = Customer(customer_name)
self.customers.append(customer)
while True:
print("\n1. Browse Restaurants\n2. View Cart\n3. Place Order\n4. Track Orders\n5. Exit")
choice = input("Choose an option: ")
if choice == "1":
customer.browse_restaurants()
elif choice == "2":
customer.view_cart()
elif choice == "3":
customer.place_order()
elif choice == "4":
customer.track_orders()
elif choice == "5":
print("Thank you for using the Food Delivery System! Goodbye!")
break
else:
print("Invalid choice! Please try again.")
# Start the system
if __name__ == "__main__":
app = FoodDeliverySystem()
app.start()