#C13778. Inventory Management System
Inventory Management System
Inventory Management System
This problem requires you to implement an inventory management system for a retail store. You are given a set of commands to be processed, which simulate operations on the inventory.
You need to implement two classes (or their equivalents) in your chosen language:
Product
: Represents a product with attributes: product ID, name, category, price, and quantity. The value of a product is defined as \(price \times quantity\).InventoryManager
: Manages a collection of products and supports the following operations:- ADD: Adds a product. If a product with a given ID already exists, you may assume the input is valid and that this case will not occur.
- UPDATE: Updates the quantity of an existing product.
- REMOVE: Removes a product.
- TOTAL: Computes the total inventory value, i.e. \(\sum_{p} (price_p \times quantity_p)\).
- HIGHEST: Finds and prints the product ID of the product with the highest value; if the inventory is empty, output
None
. - SUMMARY: Groups the products by category and prints, for each category (in alphabetical order), the total number of products and the total value.
Input is read from standard input and output is written to standard output.
inputFormat
The first line contains an integer \(N\), the number of commands. The following \(N\) lines each contain a command. The commands are in one of the following formats:
- ADD id name category price quantity — Add a product with the given details.
- UPDATE id quantity — Update the quantity of the product with the given id.
- REMOVE id — Remove the product with the given id.
- TOTAL — Print the total inventory value.
- HIGHEST — Print the product id of the product with the highest value. If the inventory is empty, print
None
. - SUMMARY — For each category (in alphabetical order), print a line with the category name, the number of products in that category, and the total value of products in that category.
outputFormat
For each command that requires output (TOTAL
, HIGHEST
, and SUMMARY
), print the result in the order the commands are given. Each output should be printed on a new line. For the SUMMARY
command, print one line per category.
7
ADD 1 Apple Fruit 1.5 100
ADD 2 Orange Fruit 2.0 50
TOTAL
HIGHEST
SUMMARY
UPDATE 2 60
TOTAL
250.0
1
Fruit 2 250.0
270.0
</p>