Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint: Inventory Line

โญ beginnerโณ 45 min read๐Ÿ“ Lesson 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:

  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.