Vending Machine
Model a vending machine with the State pattern so each state owns its own behaviour and transitions.
Requirements
Clarify, then fix the scope:
- The machine has slots, each with a code (
A1), a product, a price and a quantity. - A customer inserts money, selects a slot, and receives the product and change.
- The customer may cancel before selecting and gets all money back.
- A technician can put the machine out of order. While out of order, it accepts no money.
- Money is whole rupees in coins of 10, 5, 2 and 1.
Out of scope: card payments, the machine's own coin stock, restocking screens, hardware.
1 of 7