#K93737. Vending Machine Manager

    ID: 38486 Type: Default 1000ms 256MiB

Vending Machine Manager

Vending Machine Manager

You are required to simulate a vending machine system. In this problem, you will implement a VendingMachine that supports three operations: displaying items, purchasing an item, and restocking an item. The vending machine starts with a list of items, each with a name, price, and quantity. When processing a purchase, if the provided money is less than the price, output "Insufficient funds"; if the item is out of stock, output "Item out of stock"; and if the item does not exist, output "Item not found". When an item is successfully purchased, the change is computed using the formula \(\text{change} = \text{money} - \text{price}\) and the quantity of the item is decreased by one. For the restock operation, if the item exists, increase its quantity and output "Item restocked successfully"; otherwise, output "Item not found".

inputFormat

The first line contains an integer n that denotes the number of items in the vending machine. The next n lines each contain three values: the item name (a string), the price (a float), and the quantity (an integer), separated by spaces. The following line contains an integer q representing the number of commands. Each of the next q lines is a command that can be one of the following:

  • DISPLAY: Print the list of items.
  • PURCHASE <item_name> <money>: Attempt to purchase the specified item with the given amount of money.
  • RESTOCK <item_name> <quantity>: Increase the item's quantity by the specified amount.

outputFormat

For each command, output the result on a separate line. For the DISPLAY command, output each item on a separate line in the following format: Item: {name}, Price: ${price}, Quantity: {quantity} where the price is printed with two decimal places. For the PURCHASE command, output the change (if the purchase is successful) or the error message (Item not found, Item out of stock, or Insufficient funds). For the RESTOCK command, output either Item restocked successfully or Item not found.

## sample
3
chips 1.5 10
chocolate 2 5
soda 1.75 8
1
DISPLAY
Item: chips, Price: $1.50, Quantity: 10

Item: chocolate, Price: $2.00, Quantity: 5 Item: soda, Price: $1.75, Quantity: 8

</p>