Step 1: Requirements
Requirements
Questions to ask the interviewer
- What payment methods — coins, notes, card?
- Multiple products or just one?
- Does it give change?
- Do we need inventory tracking?
- Admin refill and cash collection?
Functional requirements
- Machine holds multiple products in slots, each with a price and quantity.
- User inserts money, selects a product, and receives it.
- Machine returns change if overpaid.
- States: Idle → HasMoney → Dispensing → ReturningChange.
- Admin can refill products and collect cash.
- Reject if insufficient funds or out of stock.
Non-functional requirements
- State transitions must be safe (no dispensing without payment).
- Extensible to new payment methods.
Assumptions
- Cash-only for simplicity (card adds a payment gateway).
- Exact denomination tracking not needed — just total amount.