Question: Specifications for the Pizza class. The implementation of this class is almost simplistic! All of the methods ( except two ) are only single code
Specifications for the Pizza class.
The implementation of this class is almost simplistic! All of the methods except two are only single code statements. My class implementation is only lines of code.
Class attributes
Remember that class members do not have a "self" prefix and are accessed with the class name and the dot operator.
Valid sizes for pizza contained in a collection at the class level.
You get to figure out the type of collection to store the sizes below.
Valid sizes are small, medium, large and xlarge.
Another class level collection having the prices for each valid size.
You get to decide on the type of collection to store the prices below.
Prices are small: $ medium: $ large: $ xlarge: $
Constructor
Instance methods have an implicit first argument "self".
A constructor that takes a default size of medium and topping of a list of cheese that does the following:
a Set the first argument size to the instance attribute size. Size must be verified. This can be done by setting the size property.
b Creates an instance attribute a list with the second argument. If the second argument is missing, a single cheese topping is inserted in the list.
Instance methods
Instance methods have an implicit first argument "self".
A method that takes an argument of type list of strings. It adds topping to the list of pizza toppings.
Implement the str method to return a formatted string. Examine the output from the test harness for clues on how to implement this method.
Instance Properties
Instance properties have an implicit first argument "self".
A property that returns the price of the pizza.
a Price is based on the size as well as the number of toppings.
See spec# for cost based on size. Each topping cost an additional $ each.
A property that returns the size of the pizza.
A property that sets the size of the pizza.
a Size must be verified. A ValueError exception is raised if the size is invalid.
Instance Attributes
All of the following Instance attributes are initialized in the constructor from the values of the argument. Notice the prefix to make is private.
size is a str that stores the size of this object. This is initialized in the constructor. It is mutated by the property in # It is returned in # It is used in # to calculate the cost of the pizza.
toppings a list of string that represents the toppings for this object. This is initialized in the constructor. It is mutated in the add method and is used in # to calculate the cost of the pizza.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
