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.
Back to lesson: Checkpoint: Inventory Line