Inventory service
Inventory service brief
Mara, the operations lead at Alder Equipment, needs a small stock service for a reservation interface. The inputs are an opening quantity, storage capacity and an ordered array of actions. Use original in-memory records only. Deliver one Solution class whose Stock object protects its quantities and reports available units, reserved units, rejected operations and availability status. Every step preserves the earlier rules. Counts are small enough to avoid arithmetic overflow, capacity is nonnegative, and normalized opening stock never exceeds capacity once capacity checks are introduced.
Build one in-memory service for a fictional equipment supplier. You will keep the same solve signature throughout, while its nested Stock object gains rules. The action stream uses a positive number for a receipt, a negative number for a reservation request and zero for releasing all reservations. Capacity is supplied from the first step but becomes enforced only when that step asks for it.
Each step starts with the previous complete solution, including your carried source. Preserve the behavior already introduced while adding the new requirement. Failed operations must change only the rejection counter. Reserved items still occupy storage, even though they are unavailable to a new reservation. The last step returns a labeled report that another part of the application could display. There is no database or network service in this project.
Stock stock = new Stock(initial, capacity);
for (int action : actions) stock.apply(action);
return stock.report();
The entry method delegates state transitions to the stock object.