CyberStars

Recap: Inventory Tracker

Combine ArrayList, HashMap, and Collections.sort()


Mission: The Vice City Arsenal

Tommy tracks the weapons he bought from Phil Cassidy over a week. He has a list of purchases: Pistol, Shotgun, Pistol, Automatic, Shotgun, Pistol, Automatic. He wants to know how many of each weapon he bought, which weapon was bought the most, and a sorted list of weapons bought more than once

Store the purchases in a String[] purchases array. Count each weapon in a HashMap. Find the weapon with the most purchases ("Most bought: X"). Collect weapons bought more than once into an ArrayList, sort it alphabetically with Collections.sort, and print everything ("Popular (sorted): [...]")

Example (first lines order may vary)

Pistol: 3
Shotgun: 2
Automatic: 2
Most bought: Pistol
Popular (sorted): [Automatic, Pistol, Shotgun]