Skip to main content

Checkpoint: Inventory Line

Challenge on lesson: Checkpoint: Inventory Line

The Inventory Line — a modeling checkpoint. Inside Solution: 1. enum Category { FOOD, ELECTRONICS, BOOKS } 2. record Item(String name, int quantity, Category category) with a compact constructor rejecting blank names, negative quantities, and null categories. 3. static int stockValue(java.util.List<Item> items, Category c) — the total quantity of items in the given category. 4. 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.

Difficulty: beginner

Back to lesson: Checkpoint: Inventory Line