Question
Python You will use information read from one text file to create instances of a class named InventoryItem. Next, you will read information from a
Python
You will use information read from one text file to create instances of a class named InventoryItem. Next, you will read information from a second text file to update information about the quantities of these inventory items. Finally, you will use the information in the list of InventoryItem objects you created and updated to prepare a report that is written to an output file showing the inventory quantities and their total values as well as the overall total value of all these inventory items.
Start by designing a class called InventoryItem. This class contains the following private data attributes:
item_number, a unique number used to identify each item
description, the text description of the item
quantity, the number of items in the inventory
unit_cost, the value of a single unit of this item in dollars and cents
The InventoryItem class has the following methods:
An initialization method (__init__) that can be used to create an instance of the InventoryItem class. All the data attributes must be specified as arguments. This method guards against initializing the quantity to a negative number.
A __str__ method that returns a string displaying the objects state.
A receive_items method that accepts as an argument the quantity of the item to be added to any existing quantity.
A ship_items method that attempts to reduce the quantity of the item. This method must not reduce the quantity of an item below zero. If an argument is passed to this method that would reduce the quantity below zero, a warning message will be displayed instead.
A set_quantity method that accepts as an argument a new quantity value for the inventory item. This method must also guard against setting the quantity to a value that is less than zero.
A get_item_number method that returns the value of the item_number.
A get_description method that returns the value of the description.
A get_quantity method that returns the value of the quantity.
A get_unit_cost method that returns the value of the unit_cost.
Place the class definition for InventoryItem in a separate file named inventoryitem.py and then include an import inventoryitem statement in your program to gain access to the class definition.
Python program will read and process two input files and create a single output file in addition to limited console output. Program will read the contents of a file named items.txt and use a portion of the contents to initially create and define the inventory item objects.
The items.txt text file contains the definition of several inventory items. Each record in this file holds the following information in this order:
item_number
description
quantity
unit_cost
The fields in this file are comma-separated. That is, each field is separated from the next field by a comma.
items.txt
12345,Ballpeen Hammer,25,18.75 56789,Phillips Screwdriver,120,10.95 24680,Claw Hammer,35,15.98 13579,Box Wrench,48,20.35 28967,Hex Wrench,70,19.98 90909,Wide Paintbrush,107,17.45 30127,1/4 inch Drill,16, 34.89 44021,3 inch Trowel, 38, 10.74 29037,1 inch Paintbrush, 73, 2.95
Although this file contains definitions for all the items in the companys entire inventory, your program will only process the subset of records where the value of the item_number is in the range from 20000 to 79999.
After creating instances of the InventoryItem class, display a line on the console (screen) reporting how many inventory items were created. Your program will then read and process a file named activity.txt. The activity.txt text file contains transactions that will potentially change the quantities of individual inventory items. These are the codes used for the possible transactions:
D Define the quantity of an inventory item
R Receive an additional quantity of an inventory item
S Ship a quantity of an inventory item
Records within the activity.txt text file contain the following comma-separated fields:
Transaction code (D, R, or S)
item_number
quantity
activity.txt -
D,12345,0 R,12345,100 S,12345,45 D,24680,0 R,24680,100 S,24680,45 X,24680,123
Process only records in the activity.txt file that effect items you defined earlier (using the items.txt file) AND contain a valid transaction code (D, R, or S). Keep track of the total number of records processed as well as the number of records that were skipped either because they did not have a valid transaction code or they dealt with an inventory item that was not defined earlier (using the items.txt file).
After processing the entries in the activity.txt file your program can now display two items on the console (screen) using print statements. You will know and can display the total number of records processed as well as the number of records skipped.
The final step in this programming project is to calculate and display the inventory value of each item as well as the grand total of all the inventory items. This information will be written to an output text file named Report.txt. The first line of inventory report will contain a made-up name for the company such as The Albatross Company, Ltd. The second line will contain the phrase, prepared on: followed by the current date and time. The third line will be blank. The fourth line is where the heading information begins. Inventory report will look as much like this as possible:
Joe E. Bagadonutz for the Albatross Company, Ltd.
Prepared On: Thursday, May 31, 2018 at 05:36:15
I N V E N T O R Y R E P O R T
Inventory Item
Number Description Quantity Unit Price Value
------ -------------------- -------- ---------- ------------
56789 Phillips Screwdriver 120 10.95 1,314.00
24680 Claw Hammer 55 15.98 878.89
28967 Hex Wrench 70 19.98 1,398.60
30127 1/4 inch Drill 16 34.89 558.24
44021 3 inch Trowel 38 10.74 408.12
29037 1 inch Paintbrush 73 2.95 215.35
============
Total $4,773.21
Once the inventory report is complete, display the overall dollar worth of all items in the inventory on the screen.
Guideline:
Correctly define all the private data attributes in the InventoryItem class.
Correctly define the __init__ method in the InventoryItem class.
Define a __str__ method that completely describes the object in the InventoryItem class.
Correctly define all the methods in the InventoryItem class.
Process only the requested entries from the items.txt file
Correctly create the inventory items from the items.txt.
Report the number of inventory items created on the screen.
Correctly process the transactions in the activity.txt file
Skip records in the activity.txt file that need skipping.
Correctly report on the screen the total number of records processed from the activity.txt file as well as the number of records skipped.
Create the Report.txt file with correct title and date and time.
Calculate and display the individual inventory item values in the report file.
Calculate and display the overall inventory value in the report file.
Also, display on the screen the overall total inventory value.
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