Checkpoint: Inventory Line
beginner45 min readLesson 43 of 180
An enum, a validated record, category stock totals, and guarded merging — modeling decisions with teeth.
The Inventory Line — a modeling checkpoint.
Inside Solution:
enum Category { FOOD, ELECTRONICS, BOOKS }record Item(String name, int quantity, Category category)with a compact constructor rejecting blank names, negative quantities, and null categories.static int stockValue(java.util.List<Item> items, Category c)— the total quantity of items in the given category.static Item merge(Item a, Item b)— combine two items of the SAME name and category into one with the summed quantity; different name/category → IllegalArgumentException.
The design question being tested: which type for each concept, and why records make merge/compare trivial.