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 M4Pro!
I must point out however that what youll be required to do here is somewhat different but having M4Pro 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 5 elements, one for author.
Also notice that each element(author 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:
1. You will create 2 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 author_name (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 book_name(must be defined when instance is created)
o year_pub(must be defined when instance is created)
o price(must be defined when instance is created)
o quantity(must 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
2. Define necessary methods for each one of the two classes, should include the following
For the Book class:
a set_total 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 M4Pro)
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.
3. Add a create_instance() function to the M4Pro 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 set_total() 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.
4. Add write_instance() 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 object/instance
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?
5. When program is executed, the following menu will be displayed (Notice its exactly the same as what was requested in M4Pro)1) Display Book Inventory and Calculate Total
2) Lookup by Author and Get Total
3) Lookup by Book Name and Get Total
4) Lookup By Price Range
5) Exit
Enter choice:
Part 1(85 points)
6. if \(\mathbf{l}\) is entered, the following should be done:
- the program is still to display the inventory content as requested in M4Pro.
- the createinstance function should be called. (this is the function you were requested to create in step 3 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 book_inventory.csv
7. if user enters 2, we w Again use class getters or the
For this assignment, you will be building on M 4

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!