Homework

Homework — a map in your app

YOUR app: counting and instant lookup with a map.

Requirements:

  1. Add a category-like field to your Item that fits your theme — Category (books), Genre (movies), Type (expenses), Muscle (workouts)… Ask for it in "Add".
  2. Count by that field. Add a menu action that builds a map[string]int with the m[k]++ pattern and prints each group's count. Accept that the print order is random — don't fight it.
  3. Find by key. Add a lookup that builds a map[string]Item (index by title/name) and uses the comma-ok idiom (it, ok := index[key]) to print the record or "Not found." — never a blank one.
  4. Read input with readLine so multi-word keys work, and gofmt + a working go run.

Extra (for those who want more): show the random order on purpose — range your counts map, print the categories on one line, run the program twice, and paste both lines. They should differ. Then explain, in one sentence, why that's Go working correctly and not a bug.

To submit: the code + a transcript showing: (1) items added in at least two categories, (2) the by-category counts, (3) one successful find and one "Not found."

Tip. You now have three ways to hold data: a struct (one record, fields by name), a slice (many records, by position), and a map (values by key). Real programs mix all three — a slice of structs you also index with a map is the everyday shape. Next milestones build on exactly this.