Prototype: changeDue(long price,long paid) requires nonnegative values and paid >= price; return paid-price or raise.

Final: construct VendingMachine from unique nonempty product codes, positive prices, and nonnegative stocks. insert requires positive amount and returns accumulated credit. select returns Receipt(code,change), decrements stock, and clears credit; missing code raises NoSuchElementException, sold-out/underpaid raises IllegalArgumentException. refund() clears and returns credit. inventory() is a fresh map of immutable Item records. Empty inventory is valid; no restocking.

The complete public API is in Exercise.java. All domain classes are public static nested classes of Exercise; construct them as new Exercise.ClassName(...). Do not implement a solution in the test runner. Each instance owns independent state. Unless explicitly allowed, null inputs are outside the domain. Failed operations leave state unchanged; validation happens before mutation.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.

Java runs on this device with CheerpJ 4.3.