Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this assignment the due date is Saturday, Feb 27. Thank you. Instructions You will need to create six files: Pizza.py -

I need help with this assignment the due date is Saturday, Feb 27.

Thank you.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Instructions You will need to create six files: Pizza.py - Defines a Pizza class representing commonality for all Pizzas. For simplicity, this class will assume all Pizzas have a size and price CustomPizza.py - Defines a child class of Pizza. This class should inherit all fields 1 methods from the Pizza class, but also introduces the concepts of toppings a customer can order (represented as a list of strings] SpecialtyPizza. py - Defines a child class of Pizza. This class should inherit all fields I methods from the Pizza class. Specialty pizzas are defined by a name attribute and all have a set price depending on the pizza size PizzaOrder. py - Defines a class that is a collection of pizza objects the customer wants to order. The total price for the order can be derived from each individual pizza price. This class will also have an expected time of when the customer would like their pizzas ready for pickup. More details on this later in the writeup Orderclueue. py - Defines a MinHeap to organize and process Pizza Orders according to their expected time of pickup. You can adapt the Heap implementation shown in the textbook supporting the specifications in this lab. testFile.py - This file will contain your pytest functions that tests the overall correctness of your class definitions There will be no starter code for this assignment, but rather class descriptions and required methods are defined in the specification below. You should organize your lab work in its own directory. This way all files for a lab are located in a single folder. Also, this will be easy to import various files into your code using the import it from technique shown in lecture. Pizza.py The Pizza. py file will contain the definition of a Pizza base class. We will define the Pizza attributes as follows: price - float that represents the price of a pizza. Since the price will be defined by what type of pizza is ordered, we can simply create the price field and initialize it to 0.0 size - str that represents the size of the pizza being ordered. For simplicity, we can have three valid pizza sizes and and label these with "S" for small, "M" for medium, and "L" for large You should write a constructor that allows the user to construct a Pizza object by passing in values for the size. Your constructor should also create a price attribute and set it to 0.0. __init__lse1f, size] Your Pizza class definition should also support the \"getter" and "setter" methods for the price and size. Since this will be a base class for other Pizza types, anything we write here can be inherited by its child classes. getPricelself) setPricel self, price) getSize l self) setSizelself, size) CustomPizza.py and SpecialtyPizza.py Pizza objects can be two different types. Both of these types of pizzas inherit from the Pizza class: 1. CustomPizza that allows the customers to add additional toppings of their choosing 2. SpecialtyPizza that has already been pre-configured and has a fixed price based on its size CustomPizza.py Your CustomPizza class definition will be defined in CustomPizza. py. The CustomPizza class will contain a constructor that takes in the size of the Pizza, and should use this size to call our base class' constructor. In addition to the size, it will initialize a toppings list represented as a Python List. The price of a CustomPizza is defined by two things: 1. the size of the pizza 2. the number of toppings the pizza will have (assuming no toppings is a simple cheese pizza). CustomPizzas will have the following fixed prices based on its size: Small (S): $8.00 Medium (M): $10.00 Large (L): $12.00 The size of the pizza also dictates the amount each additional topping will cost based on the following definition: Small (S): + $0.50 per additional topping Medium (M): + $0.75 per additional topping Large (L): + $1.00 per additional topping Since we now know what the price of a pizza should be based on the size, the CustomPizza constructor should determine the base price of the pizza and set it appropriately (remember, no need to write it in this class if we already have the method in Pizza. py). _init_(self, size) There are two more methods this class should support: addTopping(self, topping) - this method will add to the toppings list and update its price appropriately. The topping parameter is represented as a str type getPizzaDetails(self) - this method will construct and return a string containing the details of the CustomPizza object including the size, toppings, and price of the CustomPizza. An example (with escape characters shown for formatting) is given below. When constructing your string, please follow the EXACT format since this is what Gradescope will expect CustomPizza without toppings example: cp1 = CustomPizza("S") assert cp1. getPizzaDetails() == \\ "CUSTOM PIZZA\ \\ Size: S\\\\ Toppings : \\\\ Price: $8. 00\\" CustomPizza with a list of toppings example (note that each topping will be indented with a tab): cp1 = CustomPizza("L" } cp1. addTopping ("extra cheese") cp1. addTopping ("sausage" ) assert cpl. getPizzaDetails() == \\ "CUSTOM PIZZA\\\\ Size: Lin\\ Toppings : \\m\\ \\t+ extra cheese\\\\ \\t+ sausage\\\\ Price: $14. 00\\m"SpecialtyPizza.py it. SpecialtyPizza class definition will exist Tn SpecialtyFizzo.py. Similar to a CustomFizza obIect, the class constructor will take in a size as well as the name for the specialty pizza. 0 _1nit_[se1f, size, name! Also similar to the CustomF'izze c|ass.5pecia1tyPizza will use the size to set its price appropriately. The price of a SpecialtyPizze is defined as follows: - Small t5}: $12.00 - Medium {Mk $14.00 in Large {L}: $16.00 Unlike custom pizzas. specialty pizzas do not have a list of toppings associated with itI but do have a unique name that will be displayed when getting details for this pizza. This class should also have its own getPizzaDetaits method described below: - getPizzaDetaiLsisetrl this method will construct and return a string containing the details of the SpecialtyPizza object including the size and name of the SpecialtyFizza. An example {with escape characters shown for formatting] is given below. When constructing your string, please follow the EXACT format since this is what Gradascopa Itrill expect A sample output test for getFizzeDetailst J: spt - SpecialtyPtzzai"S". "Earnsmore":I assert sp1.aetPizzaDetai'Ls .- it "SPEEIALTY PIZZA'tn't Size: 5\ \\ Hale: Carnemore'tn't Price: $12.Bii\ " PizzaOrder.py The Pizzarder class will be defined in Pizzarder.py. This class will keep track of various pizzas for single order. The Pizzardcr class will have the following attributes: - pizzas - a Python List containing all the pizzas that the single order contains. This can be initially set to an empty list . tile - an int representing the expected time the order will he piclted up. This field is what will be used in determining the priority of orders. So it is possible for an early order to be daprioritized based on when the pizza is expected to be ready The constructor for a Pizzaiirder will take in the expected time that order should be ready: I ___init__t5elf. timei The time format will be stored as an int in a 24-hour time format. For example, given a hour:minute: second format. the corresponding int values would be: 0 12:00:00 AM > 0 o 9:25132 AM > 92532 0 1:14:23 PM > 131423 0 10:56:59 PM :- 225559 In addition to the constructor, setters .-' setters for the time attribute, the ability to add Pizza objects to the order. as well as a method to construct a string representing the order details will need to be implemented: 0 getTimeisetfi 0 setTirneisett. time} - sddPizzatself, pizza] - will add the Pizza object to the and of the Python List - gatorderDascriptioniselfi - constructs and returns a string containing the time of the orderI all information for each pizza in the order' as well as the total order price. Since we're storing various Pizza objects in this class' we can utilize polymorphism and simply call the getPizzaDetaiLsi} method on the Pizza objects when constructing the string for our entire order, as well as getPricel} to compute the Pizzarder total price An example of the getOrderDescription () string format is given below: cp1 = CustomPizza("S") cp1. addTopping ("extra cheese" ) cp1 . addTopping ("sausage") sp1 = SpecialtyPizza("5", "Carne-more") order = PizzaOrder(123000) #12:30:00PM order . addPizza ( cp1) order . addPizza (sp1) assert order. getOrderDescription ( ) == \\ Order Time: 123000\\\\ CUSTOM PIZZA\ Size: S\\\\ Toppings : \ \\ t+ extra cheese\ \\ \\t+ sausage\\\\ Price: $9.08\\m\\ ---\\m\\ SPECIALTY PIZZA\\\\ Size: S\\\\ Name: Carne-more\ \\ Price: $12. 80\\m\\ In\\ ----\\\\ TOTAL ORDER PRICE: $21. 00\\m\\ *****\\" OrderQueue.py The OrderQueue class will be defined in OrderQueue. py. This priority queue is implemented as a MinHeap data structure. The OrderQueue will manage PizzaOrder objects based on their time attribute. _init_(self) - the constructor for the OrderQueue will simply initialize the Python List representing the MinHeap. Since it's possible to remove from an empty OrderQueue, we will create and raise an exception when this is done. You will define a QueueEmptyException class in OrderQueue. py that doesn't do anything except define an Exception object to raise when this happens (recall, we did do an example of defining basic Exception class types - you can refer to lect06 notes). In addition to the construction of the MinHeap in this class, two methods are required to be implemented: addOrder(self, pizzaOrder) - a pizzaOrder object will be stored in the MinHeap prioritized by its time attribute (lower value means higher priority) processNextOrder(self) - this removes the root node from the MinHeap (and restructures the MinHeap), and returns a string containing the root value's pizza order description The automated tests will create various pizza orders with different time attributes. It will then call processNextOrder one at a time and check the removed PizzaOrder is in the right priority by checking their expected getOrderDescription() string. You should write similar tests to confirm the MinHeap state is in the correct order

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions