Preparing your design workspace

Loading the problem and your saved attempt…

Design a Snack Vending Machine: Cash, Change, and Expiring Stock

Model slot selection, cash payment, exact change from a limited coin box, refunds, and a rule that expired units are never sold.

For this exercise, assume a single snack machine that sells packaged items and takes cash only. Its slots have short codes such as A1 to D6. Each slot holds one product at one price, and the units in a slot sit in a line that the machine releases front first.

Every unit has its own expiry date; a unit may still be sold on that date and is expired from the next day.

A customer first chooses a slot and sees the price, then inserts coins and notes one at a time. Accepted money is 5, 10 and 25 cent coins, 1 dollar coins, and 1 and 5 dollar notes. As soon as the inserted total covers the price, the machine releases one unit and pays back any difference.

Until a unit is released, the customer may cancel and get back exactly what they put in.

For this exercise, also assume these rules: - Never sell an expired unit. If the chosen slot is empty or its front unit is expired, the selection is refused before any money goes in. - Change is paid only from cash the machine holds, which includes what this customer has inserted.

If exact change cannot be paid, the sale does not happen and everything the customer inserted is returned. - If the release mechanism reports that the unit did not drop, the customer gets a full refund and the unit stays in its slot. - One customer uses the machine at a time.

- An operator restocks slots with dated units, removes expired units, and adds or collects cash. The machine does not sell while the operator has it open.

Out of scope: card or phone payments, discounts, network reporting, fleets of machines, and the hardware itself. Treat the coin acceptor, the change outlet and the release mechanism as devices your software talks to.

Design the object model, the public contracts and the purchase flow. This is a design exercise; no code is required.