Question: For this assignment, you will be building on M 4 Pro! I must point out however that what you ll be required to do here
For this assignment, you will be building on MPro!
I must point out however that what youll be required to do here is somewhat different but having MPro done would certainly save you time.
So whats what will we do different here?........
Well lets first start by going over the inventory dictionary, see image below
Notice that the inventory dictionary references elements, one for author.
Also notice that each elementauthor name points to a list of dictionaries, with each dictionary referencing information that pertains to one book.
So whats in common here?
The following information is saved for each book.
Author name
Book name
Unit Price
Quantity
Year published
After having gone over the above, lets move on to what you need to do for this assignment.
Instructions:
You will create Classes, one for author information and one for book. Refer to bullet points below on the names that you are to assign for each class.
Create a Author class. This class is to have the following attributes
o authorname must be defined when instance is created
o books a list of Book instances. Assign this attribute an empty list as a default value. Meaning passing a list of instances when creating an Author instance shouldnt be required. If not passed, the instance will reference an empty list.
o all attributes must be protected
Create a Book class. This class is to have the following attributes
o booknamemust be defined when instance is created
o yearpubmust be defined when instance is created
o pricemust be defined when instance is created
o quantitymust be defined when instance is created
o total automatically created when instance is created. Is the result of quantity multiplied by price
o all attributes must be protected
Define necessary methods for each one of the two classes, should include the following
For the Book class:
a settotal method that will be used to assign a value to the total attribute. This method is to be triggers when an instance is created in order to automatically calculate the total for each item.
getter method for each attribute. each method is to return the value that is reference in the attribute it was created for
setter method for the quantity and price attributes.
repr method This method should return a string that displays attribute information in a tabular format similar to what was requested when displaying information in MPro
For the Author class:
getter method for class attributes.
setter for the books attribute. This setter is to be used to append Book instances to the books attribute.
repr method This method is a bit tricky and you will have to do some research on it why? Well it is to returns the author name and book information book name, year published, price quantity and total remember however we already have a repr for the book instance. So what will you do
Use AI to guide you in on how to do this but you MUST use the Book class repr to display book information.
After having created the classes, lets move on to what the program should do
Add a createinstance function to the MPro program you completed.
This function should be passed the book inventory dictionary.
It is to iterate over the dictionary.
Create an Author instance for each author. Create a Book instance for each book. Remember, the A total should be automatically calculated by the settotal method for each book. The book instance should then be appended to the Authors books attribute.
the function is to return Two lists, one for Author instances and another for Books instances. Remember each list will reference the instances that were created for each class.
Add writeinstance function that does the following:
this function should be passed a list ONE list of class objects.
it iterates over the list of objects then writes the following information for each objectinstance
author name book name year published quantity price total
object information is to be retrieved using the getter methods
the created csv file should have a properly named header row
The csv file should be assigned a proper name, more details below
How will the program work?
When program is executed, the following menu will be displayed Notice its exactly the same as what was requested in MPro Display Book Inventory and Calculate Total
Lookup by Author and Get Total
Lookup by Book Name and Get Total
Lookup By Price Range
Exit
Enter choice:
Part points
if mathbfl is entered, the following should be done:
the program is still to display the inventory content as requested in MPro.
the createinstance function should be called. this is the function you were requested to create in step above
so in this step, class instance will be created for each Author. The book information is to then be written into a csv file using class getter methods Name the file bookinventory.csv
if user enters we w Again use class getters or the
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
