Question: 1 . Create a Cake class with these attributes: Variables: type # an integer size # a character weight # a float name # a

1. Create a Cake class with these attributes:
Variables:
type# an integer
size# a character
weight# a float
name# a string, e.g. "Chocolate"
recipe # a dictionary
ingrd_list # a list
Requirements related to ingrd_list :
1. It should be a nested(2-dimensional) list which includes: 1) a sub-list of the ingredient labels;2) a sub-list of the ingredient weights, like this:
[["Flour", "Sugar", ...],[10.1,15.7,...]]
2. calc_ingrd() has to be called from within __init__ to build ingrd_list.
3. Then, when the objected is to be printed, upon calling __str__, the sub-list of ingredient labels will be iterated and each label can be used directly for printing. Hint: formulate the for loop header as something like this: for ingrd_label, ingrd_wt in zip( ingrd_list[0], ingrd_list[1]) :
Methods:
__init__(self,type,size) # for object instantiation; it should also set the values for weight and name
__str__(self) # returns cake_string as the textual listing of the ingredient weights; with this you Don't need the function print_ingrd() as in Lab 7
calc_ingrd(self, weight, recipe) # to be called from within __init__(...); it doesn't need to return anything but save values to the member variables directly.
2. Write test code to instantiate cake objects, one for each type and size -6 total.
e.g.my_lrg_lemon_cake = Cake(3,'L')# instantiate a cake object
print(my_lrg_lemon_cake) # test the __str__ method
After print(my_lrg_lemon_cake) has been called, the ingredients list should be printed out in this format:
Ingredient Quantities for Large Lemon Cake
Sugar: 16.8 Oz
Egg: 10.1 Oz
Buttermilk: 10.1 Oz
Vanilla Extract: 0.2 Oz
Butter: 9.5 Oz
Sifted Self Rising Flour: 17.5 Oz
Filling - Egg Yolk: 20.0 Oz
Filling - Sugar: 12.7 Oz
Filling - Butter: 2.4 Oz
Filling - Lemon Zest: 12.8 Oz
You can remove the ordering interface part (the sentinel while loop) from Lab 7 and just create and test individual cake objects as shown above. If we want to include the ordering interface, we need to create a composition class, Cake_order, for a list of Cake objects. You can do your own research to find out how to do that, if you are interested; it is beyond the scope of this course; the code you need to write to test it will be more involved too.
You can use this block of test code for your program:
"""
**********************************************
Create and print cake objects
**********************************************
"""
reg_chocolate_cake = Cake(1,'R')
lrg_chocolate_cake = Cake(1,'L')
reg_red_velvet_cake = Cake(2,'R')
lrg_red_velvet_cake = Cake(2,'L')
reg_lemon_cake = Cake(3,'R')
lrg_lemon_cake = Cake(3,'L')
print(reg_chocolate_cake)
print(lrg_chocolate_cake)
print(reg_red_velvet_cake)
print(lrg_red_velvet_cake)
print(reg_lemon_cake)
print(lrg_lemon_cake)
Checkpoints:
Implement the Cake class with major attributes: member variables specified above, __init__(self,type,size),__str__(self) and calc_ingrd(self, weight, recipe)
Define the recipe dictionaries either as global - above the program or inside __init__()
Write test code to create/instantiate/construct 6 different cake objects- regular and large for chocolate, red velvet and lemon cakes. And, print them - display the ingredient list tables.
Paste the record of execution and output data at the bottom of the source file.
All the Documentation Requirements stated in previous lab assignments still apply; e.g. doctrings for the file header and Class and all member functions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!