In: Computer Science
The restaurant maintains the catalog for the list of food and beverage items that it provides. Apart from providing food facility at their own premises, the restaurant takes orders online through their site. Orders on the phone are also entertained. To deliver the orders, we have delivery boys. Each delivery boy is assigned to the specific area code. The delivery boy cannot deliver outside the area which is not assigned to the delivery boy (for every delivery boy there can be a single area assigned to that delivery boy). The customer record is maintained so that premium customer can be awarded discounts.
Need copy of code and a report if possible.
Code is Python.
'''we will define three classes
1.restaurant
2.delivery_boy
3.customer
'''
'''
first we will work on coustomer
we will keep record of
1. customer name
2. customer pin code
3. customer past order
4. is customer premium or not
5. the method in the order function is to check whether the order
is online or offline
mrthod:
0 - offline
1 - on phone
3 - online
'''
class customer:
def __init__(self, name, pin, is_premium =
False):
self.order = []
self.ongoing_order = []
self.name = name
self.pin = pin
self.is_premium = is_premium
def place_order(self, dish, method, delivery_boy =
None, pin = None, cost):
self.ongoing_order.append((dish,
method, delivery_boy, pin, cost))
def complete_order(self):
self.order.append(self.ongoing_order[0])
self.ongoing_order = []
'''
now for delivery boy we just see its pin and currently free or
not
'''
class delivery_boy:
def __init__(self, name, pin, is_available =
True):
self.name = name
self.pin = pin
self.order = []
self.ongoing_order = []
self.is_available =
is_available
def accept_order(self, dish, customer, pin, method,
cost):
self.ongoing_order.append((dish,
customer, pin, cost))
self.is_available = False
def complete_order(self):
self.is_available = True
self.order.append(self.ongoing_order[0])
self.ongoing_order = []
'''
now define the resaurant class
'''
class restaurant:
def __init__(name, discount = 0):
self.name = name;
self.dishes = []
self.coustomer = []
self.orders = []
self.delivery_boy = []
self.discount = discount
self.ongoing_orders = []
def add_dish(self, name, price):
self.dishes((name,price))
def add_customer(self, name, pin, is_premium =
False):
new_customer = customer(name, pin,
is_premium = False);
self.customer.append(new_customer)
def add_delivey_boy(self, name, pin, is_available =
True):
new_delivery_boy =
delivery_boy(name, pin, is_available = True)
self.delivery_boy.append(new_delivery_boy)
def place_order(dish, customer_name, pin = None, method):
#first check if customer exist
or not
for customer in
self.coustomer:
if
(customer.name == customer_name):
break
if (customer.name !=
customer_name):
raise
Exception('coustomer havent registered. Please sign up')
if (len(customer.ongoing_order)
> 0):
raise
Exception('the customer has already an ongoing order')
if (pin == None):
pin =
customer.pin
if (method != 0):
for d in
self.delivery_boy:
if (d.pin == pin and d.is_available):
break
if (d.pin !=
pin or not d.is_available):
raise Exception('delivery boy not
available')
self.ongoing_order.append(customer, d, dish, pin, method)
d.accept_order(dish, customer, pin, method, cost)
customer.place_order(dish, method, d, pin, cost)
def complete_order(self, customer):
for i in range(0,
len(self.ongoing_order)):
if
(self.ongoing_order[i][0].name = customer.name):
break
self.order.append(self.ongoing_order[i])
self.ongoing_order[i][2].complete_order
customer.complete_order
del self.ongoing_order[i:i+1]