Concepts this problem usesHidden, since spotting them is part of the practice.Show themHide
The platform
One machine, one last train
Dev Okafor manages Northgate Station. On platform 2 stands one snack machine, and at 11:48 on a Friday night it is the only food for twenty miles of track. People feed it coins with one eye on the departure board.
The machine's software is older than the station's escalators. It swallows coins when a slot is empty, and nobody can say what it will do after a cancel. Dev wants new software in it before the timetable changes next month.
What Dev wants
Coins in, a snack and change out
The machine takes coins and keeps a running balance. A customer picks a slot by its code: if the slot is stocked and the balance covers the price, the machine sells the snack and gives back the change. With too little money in, or an empty slot, it refuses and keeps the balance for another pick. Cancel gives back everything put in.
Platform 2 · Snacks
5¢ 10¢ 25¢ $1 coins accepted
- Change comes back in coins
- No bills, no cards (yet)
- Cancel returns everything inserted
A few of the slots
| Price | Left | |
|---|---|---|
| A1 Pretzels | $1.25 | 4 |
| A2 Chips | $1.00 | 0 |
| C2 Juice | $1.75 | 1 |
Last Friday
Two receipts from 11:48 pm
One commuter bought pretzels with a quarter to spare. Another tried the empty chips slot, then gave up and pressed cancel before the doors closed.
- Coins
- $1 + 25¢ + 25¢
- Picked
- A1 Pretzels
- Price
- $1.25
- Coins
- $1 + 10¢
- Picked
- A2 Chips: empty
- Then
- Cancel
Next month
Out of service, without a rewrite
Cleaning nights need an out-of-service mode, and card readers come next year. Neither should mean rewriting the machine.Dev Okafor
A technician refills the slots by hand, so there is no restocking app to build, and nothing has to be saved anywhere: when the power goes, the coins drop into the cash box.
Design the classes for the platform 2 machine.
Start building