URGENT
(In Python)
Create specified classes with following requirements. Class PizzaOrder Ability to add/remove pizza(s) An order can have more than one pizza. Ability to specify the store for which the order is made Ability to apply special promotion code Ability to check the order status Possible statuses are ORDER_CREATED, ORDER_CANCELED, ORDER_READY, ORDER_ON_DELIVERY, ORDER_COMPLETE Has customer information Class Pizza Ability to specify toppings Ability to add/remove toppings Ability to specify price Ability to specify crust type (thin/thick) Class Store Ability to hold a list of employees Ability to add/remove employees Needs to have address including zip code Needs to have phone number Needs to be able to show monthly pizza sales Class Employee Has first name, last name Class Customer Has first name, last name, phone number, zip code, frequent mileage number Note: You need to be able to sort PizzaOrder by order date and total order amount You need to be able to search PizzaOrder by customer You need to be able to search PizzaOrder by order date You need to be able to pull a list of PizzaOrder prior to a certain date in sorted order by date You need to be able to pull a list of PizzaOrder after a certain date in sorted order by date A customer must be able to find one of your stores in the same zip code For searching and sorting above, explain time/space computation complexity using Big O Notation. You are allowed to add any private attributes (properties/variables) and methods as necessary
Below are the screenshots of code & test output:
Below is the python code which contains class definitions for all the mentioned classes along with the required search and sort methods. Also these methods and classes are then tested using sample test code.
NOTE: The posted code often loses its indentation. In case the below code loses its indentation, please refer to above screenshots for proper indentation.
import operator
from datetime import datetime
import enum
#enum for status
class status(enum.Enum):
ORDER_CREATED = 1
ORDER_CANCELED = 2
ORDER_READ = 3
ORDER_ON_DELIVERY = 4
ORDER_COMPLETE = 5
#enum for crust Type
class crustType(enum.Enum):
thin = 1
thick = 2
#class for PizzaOrder
class PizzaOrder:
def __init__(self,
pizzas=[],
store=None,
promotionCode=None,
orderStatus = status.ORDER_CREATED,
customer = None,
order_date = None):
self.pizzas = pizzas
self.store = store
self.store.pizzaSales.append(self)
self.promotionCode = promotionCode
self.orderStatus = orderStatus
self.customer = customer
self.order_date = order_date
self.amount = sum(pizza.price for pizza in self.pizzas)
def addPizza(pizza):
self.pizzas.append(pizza)
def removePizza(pizza):
self.pizzas.remove(pizza)
def specifyStore(store):
self.store = store
self.store.pizzaSales.append(self)
def applyPromotionCode(promotionCode):
self.promotionCode = promotionCode
def checkOrderStatus():
print(self.orderStatus.name)
def __str__(self):
return
"=======================================================================================\n"+\
"Pizzas :\n % s\nStore :\n % s\nPromo Code applied : % s\nOrder
Status : % s\nCustomer :\n % s\nAmount : % s\nOrder Date :% s\n"
\
% (' \n'.join([str(Pizza).replace("\n","\n\t\t") for Pizza in
self.pizzas]),
str(self.store).replace("\n","\n\t\t"),self.promotionCode,self.orderStatus.name,str(self.customer).replace("\n","\n\t\t"),self.amount,self.order_date)+\
"=======================================================================================\n"
#class for Pizza
class Pizza:
def __init__(self,
toppings=[],
crust=crustType.thin,
price = 0):
self.toppings = toppings
self.crust = crust
self.price = price
def addToppings(topping):
self.toppings.append(topping)
def removeToppings(topping):
self.toppings.remove(topping)
def specifyPrice(price):
self.price = price
def specifyCrustType(crust):
self.crust = crust
def __str__(self):
return " P I Z Z A \nToppings : % s\nCrust : % s\nPrice : % s\n
"\
% (self.toppings, self.crust.name,self.price)
#class for Store
class Store:
class address:
def __init__(self,addressString = "",zipCode = "000000"):
self.addressString = addressString
self.zip_code = zipCode
def __init__(self,
employees = [],
address=None,
phoneNumber=None,
pizzaSales = []):
self.employees = employees
self.address = address
self.phoneNumber = phoneNumber
self.pizzaSales = pizzaSales
def addEmployees(employee):
self.employees.append(employee)
def removeEmployees(employee):
self.employees.remove(employee)
def getMonthlySales():
sortPizzaOrdersByOrderDate(self.pizzaSales)
if len(self.pizzaSales)>0:
curentMonth = self.pizzaSales[0].order_date.month
curentYear = self.pizzaSales[0].order_date.year
i= Amount = 0
next = True
while i<len(self.pizzaSales):
print("Report for Month",currentMonth,", Year",currentYear)
while(i<len(self.pizzaSales) and
self.pizzaSales[i].order_date.month==currentMonth and
self.pizzaSales[i].order_date.year==currentYear):
print(self.pizzaSales[i])
Amount += self.pizzaSales[i].amount
i+=1
print("Net Sales for Month",currentMonth,", Year",currentYear," =
",Amount)
if i<len(self.pizzaSales):
Amount = 0
curentMonth = self.pizzaSales[i].order_date.month
curentYear =self. pizzaSales[i].order_date.year
def __str__(self):
return " S T O R E \nEmployees : % s\nAddress : % s\nPhone No. : %
s\n "\
% (', '.join([str(e) for e in self.employees]),
"["+self.address.addressString+", Zip code:
"+self.address.zip_code+"]",self.phoneNumber)
#class for Employee
class Employee:
def __init__(self,firstName = "",lastName = ""):
self.firstName = firstName
self.lastName = lastName
def __str__(self):
return self.firstName + " " + self.lastName
#class for Customer
class Customer:
def __init__(self,firstName = "",lastName = "", phoneNumber =
None,zip_code = None, frequentMileage =None):
self.firstName = firstName
self.lastName = lastName
self.phoneNumber = phoneNumber
self.zip_code =zip_code
self.frequentMileageNumber = frequentMileage
def findStoresInSameZipCode(stores):
result = []
for store in stores:
if store.address.zip_code == self.zip_code:
result.append(result)
return result
def __str__(self):
return " C U S T O M E R \nName : % s % s\nZip Code : % s\nPhone
No. : % s\n "\
% (self.firstName,self.lastName,
self.zip_code,self.phoneNumber)
#class for sorting pizza orders by order date
def sortPizzaOrdersByOrderDate(pizzaOrders):
# since inbuilt quick sort is used T(n) = O(nlog(n))
# space complexity is O(1), since no extra space is used
pizzaOrders.sort(key = operator.attrgetter('order_date'))
#class for sorting pizza orders by Amount
def sortPizzaOrdersByOrderAmount(pizzaOrders):
# since inbuilt quick sort is used T(n) = O(nlog(n))
# space complexity is O(1), since no extra space is used
pizzaOrders.sort(key = operator.attrgetter('amount'))
#class for searching pizza orders by order date
def searchPizzaOrderByOrderDate(pizzaOrders,date):
# since linear search is used T(n) = O(n)
# space complexity is O(1), since no extra space is used
for order in pizzaOrders:
if order.order_date == date:
return order
return None
#class for sorting pizza orders by customer
def searchPizzaOrderByCustomer(pizzaOrders,customer):
# since linear search is used T(n) = O(n)
# space complexity is O(1), since no extra space is used
for order in pizzaOrders:
if order.customer == customer:
return order
return None
#class for getting pizza orders after a specific date
def getPizzaOrderAfterDate(pizzaOrders,date):
# since linear search is used T(n) = O(n)
# space complexity is O(1), since no extra space is used
pizzaOrders = sorted(pizzaOrders,key =
operator.attrgetter('order_date'))
for i in range(len(pizzaOrders)):
if pizzaOrders[i].order_date > date:
return pizzaOrders[i:]
return []
#################################################################################
### T E S T I N G
###############################################################
Thor = Customer(firstName = "Thor",zip_code = "100100")
Venom = Customer(firstName = "Venom",zip_code = "102300")
stores = [Store(employees =
[Employee("Steve","Rogers"),Employee("Bruce","Banner")],address=Store.address("New
York","100100"),phoneNumber="987654321"),
Store(employees =
[Employee("Tony","Stark"),Employee("Peter","Parker")],address=Store.address("Washington","102300"),phoneNumber="908070501")]
pizzaOrders = [PizzaOrder(pizzas=[Pizza(toppings = ["Olive",
"Capsicum"],price = 100),Pizza(toppings = ["Capsicum"],price =
200)],
store = stores[0],
promotionCode = "GETFREE",
customer = Thor,
order_date = datetime(2020,6,20)),
PizzaOrder(pizzas=[Pizza(toppings = ["Olive", "Capsicum"],price =
150),Pizza(toppings = ["Capsicum"],price = 200)],
store = stores[1],
customer = Venom,
order_date = datetime(2020,5,20)),
PizzaOrder(pizzas=[Pizza(toppings = ["Olive", "Capsicum"],price =
50),Pizza(toppings = ["Capsicum"],price = 200)],
store = stores[1],
customer = Thor,
order_date = datetime(2021,6,21))]
print("TEST1: printing created orders")
for order in pizzaOrders:
print(order)
print("TEST2: printing sorted orders by date")
sortPizzaOrdersByOrderDate(pizzaOrders)
for order in pizzaOrders:
print(order)
print("TEST3: printing sorted orders by Amount")
sortPizzaOrdersByOrderAmount(pizzaOrders)
for order in pizzaOrders:
print(order)
print("TEST4: searching orders by date")
print(searchPizzaOrderByOrderDate(pizzaOrders,datetime(2020,6,21)))
print("TEST5: searching orders by customer")
print(searchPizzaOrderByCustomer(pizzaOrders,Venom))
print("TEST6: getting orders after a specific date")
orders_after_date =
getPizzaOrderAfterDate(pizzaOrders,datetime(2020,12,12))
for order in orders_after_date:
print(order)
Get Answers For Free
Most questions answered within 1 hours.