Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Well let s first start by going over the inventory dictionary, see image below The item name Again, the reason we ask for category to
Well lets first start by going over the inventory dictionary, see image below The item name
Again, the reason we ask for category to be enter
Instructions:
You will create Classes, one for each category. Refer to bullet points below on the names that you are to assign for each class.
Create a DeskSp class. You might have guess already but DeskSp is short for Desk Supplies
Create an OfficeSp class. This class is for Office Supplies.
Create a ComSp class for the Computer Accessories category.
Next make sure that each one of the classes above has the following attributes
Itemname must be defined when creating an instance
quantity must be defined when creating an instance
unitprice must be defined when creating an instance
total automatically created when instance is created. Is the result of quantity multiplied by unitprice
all attributes must be protected
Define necessary methods for each one of the three classes, should include the following
repr method This method should return a string that consists of the following itemname quantity, unitprice and total Note that it should also allocate spaces for itemname and spaces for the remaining attributes
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 unitprice attributes.
After having created the classes, lets move on to what the program should do
Add a createinstance function to the MPro program or MPro, whichever you want to build on
This function should be passed the inventory dictionary.
It is to iterate over the dictionary and verify the category.
o If the category is Desk Supplies create a DeskSp instance for each item under Desk Supplies. Remember, total should be automatically calculated by the settotal method for each item.
o If the category is Office Supplies create a OfficeSp instance for each item under Office Supplies. Remember, total should be automatically calculated by the settotal method for each item.
o If the category is Computer Accessories create a ComSp instance for each item under Computer Accessories. Remember, total should be automatically calculated by the settotal method for each item.
the function is to return Three lists, one for each category 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 listONE list of class objects.
it iterates over the list of objects then writes the following information for each objectinstance
o item name
o quantity
o unitprice
o total
object information is to be retrieved using the getter methods defined for category.
the created csv file should have the following header row Item Name, Quantity, Unit Price Total
The csv file should be assigned the category name
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 and MPro
if 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
then the writeinstance function should be called.
so in this step, class instance will be created for each category AND list of instances for each category should be written to a separate csv file so csv files will be created here one for each category
if user enters we want the program to work a little differently. See below for details.
Call the createinstance function here too so that instances are created. This step is necessary to ensure instances are created regardless of what menu option the user chooses first
Ask the user to enter the category name then determine which list of instances to look in
For instance if the user enters Desk Supplies the program should look in the list that references the DeskSp instances.
After having determined the category iterate over list of objects and use the getter methods to retrieve and display the following.
o Item name
o Quantity
o Unit Price
Make sure the information is displayed in a tabular format remember the linked program does that already
options is to be altered the same way option was. Meaning a list of instances for each categoryclass is to be created first.
Next, ask the user to enter the following
The category of the item they are looking for
The item name
We will consider the above instead of asking for item name only in order to simplify the process. So i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started