Question

URGENT (In Python) Create specified classes with following requirements. Class PizzaOrder Ability to add/remove pizza(s) An...

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

Homework Answers

Answer #1

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)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Programming Language is Java In class you learned how to work with collections and streams. This...
Programming Language is Java In class you learned how to work with collections and streams. This lab allows you to apply the skills you learned to a list of riders. With your first two assignment complete, the coordinator at the Car Safety Academy decided to begin collecting names for a monthly mailing list. You've been asked to collect the names and perform some processing. First you will create a Riders class. Then you will create an array of riders with...
Part 1 - LIST Create an unsorted LIST class ( You should already have this code...
Part 1 - LIST Create an unsorted LIST class ( You should already have this code from a prior assignment ). Each list should be able to store 100 names. Part 2 - Create a Class ArrayListClass It will contain an array of 27 "list" classes. Next, create a Class in which is composed a array of 27 list classes. Ignore index 0... Indexes 1...26 correspond to the first letter of a Last name. Again - ignore index 0. index...
Requirements: Based on the following information, draw an E-R diagram and a set of relations in...
Requirements: Based on the following information, draw an E-R diagram and a set of relations in 3rd normal form. Please indicate any assumptions that you have made. Wally Los Gatos, owner of Wally’s Wonderful World of Wallcoverings, has hired you as a consultant to design a database management system for his chain of three stores that sell wallpaper and accessories. He would like to track sales, customers, and employees. After an initial meeting with Wally, you have developed a list...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None:...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None: """This method adds new value to the tree, maintaining BST property. Duplicates must be allowed and placed in the right subtree.""" Example #1: tree = BST() print(tree) tree.add(10) tree.add(15) tree.add(5) print(tree) tree.add(15) tree.add(15) print(tree) tree.add(5) print(tree) Output: TREE in order { } TREE in order { 5, 10, 15 } TREE in order { 5, 10, 15, 15, 15 } TREE in order {...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
Use ONLY the classes in this list to draw a Class diagram. The diagram must show...
Use ONLY the classes in this list to draw a Class diagram. The diagram must show all the classes, their attributes, and the relationships between the classes. All the associations must have proper multiplicity constraints indicated. Note that class methods and attribute types are not required.                                                                                                               Domain classes and their attributes Order [date/time, total price, status] Account [full name, address, phone, email] SellerAccount (no attributes) BuyerAccount [credit card] Book [title, ISBN, author, publisher, asking price] BookOnOrder [quantity] Dispute [reason]...
Python 3 We’re going to create a class which stores information about product ratings on a...
Python 3 We’re going to create a class which stores information about product ratings on a website such as Amazon. The ratings are all numbers between 1 and 5 and represent a number of “stars” that the customer gives to the product. We will store this information as a list of integers which is maintained inside the class StarRatings. You will be asked to write the following: 1) A constructor which takes and stores the product name. 2) A function...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer, and Store. All data members of each class should be marked as **private** (a leading underscore in the name). Since they're private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set_" followed by the name of...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...