#Vending Machine Kata#
A vending machine has
- Seven selection buttons: numbered 0 - 6
- Cancel selection and Cancel transaction buttons.
- a slot that accepts coins
- a tray for returning coins
- a hopper where the purchased items are delivered
- a two-line display; each line can show up to 20 characters. The top line is used for showing the item that has been selected and the bottom line for showing the amount of money required to make a purchase
- capacity for 30 products, which are arranged in 5 rows of 6. Each product has a code in the form , 0[row][column], e.g. 012 represents the 3rd product in the 2nd row. Each is priced individually.
The machine allows users to select the item they want to buy by keying in the three-digit item code using the numbered keys, and inserting coins to cover the cost of the item. Once the machine has received a valid selection and sufficient money, it immediately sends the purchased item to the hopper and any change to the coin tray.
The vending machine behaves like this
- When it first starts up, it enters the ready state. In this state, the machine displays “Ready”.
- A user must key in a three-digit code using the seletion buttons to form a complete selection. If the selection buttons are pressed just once or twice, the selection is incomplete, and the machine displays “Selection incomplete: xy” where xy is the incomplete selection.
- Once a complete selection of three digits has been keyed in, the machine changes its display; if the selection is a valid one, it displays “Selected: xyz”. If the selection is invalid, the machine displays “Selection invalid: xyz”.
- Once a complete selection (valid or invalid) has been keyed in, subsequent presses of the selection buttons changes the selection by shifting the digits left. So, when wxy is selected and the z button is pressed, the selection changes to xyz.
- At any time, pressing Cancel selection sets the machine to the state it would have had had no selection buttons been pressed.
- The user may insert coins into the machine at any point: before, during or after entering their selection.
- If the current selection is valid and insufficient money has been inserted to buy the selected item, the machine displays “Insert “ followed by the amount of money the user must still insert to make the purchase.
- If the current selection is incomplete or invalid and some money has been inserted, the machine displays “xy inserted” where y is the total value of the inserted coins.
- If the current selection is incomplete or invalid and no money has been inserted, the machine doesn’t display anything about money.
- If at any time, the Cancel transaction button is pressed, the machine returns all the coins inserted since it was last in the ready state to the coin tray, cancels the current selection and returns to the ready state.
- If at any time, the machine has a valid selection and amount of money inserted is sufficient to purchase the selected item, the machine immediately transfers the item to the hopper, sends any change to the coin tray and returns to the ready state.