Vending machine

Start from ready-to-use Eclipse project VendingProject.zip (follow the instructions)

Implement a system to manage a dispenser selling canned beverages (using Java Collections). The system must meet the following requirements.

R1: Beverages

The vending machine can distribute several types of beverages. Each beverage is characterized by its unique name and the selling price. For instance:

Beverage
name
Selling
price
Coke
0.50
Water
0.30
Beer
1.00

Method addBeverage() of class VendingMachine let the administrator to add the description of a new beverage. To obtain the price of a beverage, the method getPrice() is provided. If a price is requested for a beverage name that does not exist, the method returns an error code (e.g., -1.0).

R2: Payment cards

The vending machine works by means of payment cards. Each card is characterized by a unique ID (integer number) and the available credit. For instance:

Card ID
Credit
12 5.5
21 10.0
99 0.75

Cards are recharged through the method rechargeCard() of class VendingMachine. If a non-existing ID is provided a new card is created, otherwise the existing card is recharged. Further, it is possible to query the available credit of a given card with method getCredit(). If a non-existing card ID is queried, the method returns an error code (e.g., -1.0).

R3: Machine refill

The vending machine is made by 4 columns, each containing cans of a particular type of beverage. Each column is characterized by the type of beverage and the number of cans currently available. The same beverage can be present in multiple columns (but each column contains only one type of cans). At start-up columns are empty. When the machine is refilled, each column is assigned with a beverage type and the quantity of available cans. To this aim method refillColumn() is provided. Columns are numbered starting at 1. For instance:

Column
number
Beverage
name
Number of
cans
1
Coke 1
2
Beer 10
3
Coke 15
4
Water 20

Given the name of a beverage (e.g., "Coke") it is possible to obtain the total number of available cans for a given beverage by means of method availableCans(). The method counts all columns containing cans of the given type of beverage.

R4: Selling

The vending machine sells a product by specifying the beverage name and the payment card ID in method sell(). The method returns the colum where the can was picked from. If codes are invalid (either beverage or card), the beverage ran out, or credit on payment card is not enough to buy the requested item, an error code is returned (e.g., -1). On normal behavior, the machine decrements the credit on payment card and the quantity of available cans for the selected column. Note that the machine selects the first column with available cans of the requested type.