#K33302. Simple Inventory Management System
Simple Inventory Management System
Simple Inventory Management System
You are required to implement a simple inventory management system for a small retail store. The system supports the following commands:
- ADD ITEM_NAME QUANTITY PRICE: Adds an item to the inventory with the given quantity and price. If the item already exists, its quantity is increased by the given amount.
- REMOVE ITEM_NAME QUANTITY: Removes the specified quantity of an item. If the item does not exist or if the quantity to remove is more than available, output an error message.
- GET ITEM_NAME: Retrieves the current quantity of the item. If the item does not exist, output an error message.
- LIST: Lists all items in the inventory in lexicographical order. Each item is displayed in the format:
ITEM_NAME: QUANTITY PRICE: PRICE
with the price formatted to two decimal places.
The commands are provided via standard input and the responses should be printed to standard output. Note that some commands may not produce an output unless there is an error or a query command is executed.
The error messages are exactly as follows:
- If trying to remove more than available:
ERROR: Insufficient quantity
- If the item does not exist in cases of removal or retrieval:
ERROR: Item does not exist
</p>
- ADD ITEM_NAME QUANTITY PRICE
- REMOVE ITEM_NAME QUANTITY
- GET ITEM_NAME
- LIST
inputFormat
The first line of input contains an integer N representing the number of commands. Each of the following N lines contains a command. The commands can be one of the following:
outputFormat
For each command that produces an output (i.e. GET, REMOVE when an error occurs, or LIST), print the output. Each output should be printed on a new line. For the LIST command, if there are multiple items, print the result on one output block with each item on a new line.
## sample2
ADD APPLE 10 1.5
GET APPLE
10
</p>