Skip to main content

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:

  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.