Station Status Board – Task 3
The query system you built has become indispensable. Crew members across the station rely on it to check subsystem status throughout their shifts. But the chief engineer has noticed something about how different programmers have implemented the lookup functionality, and she wants to share an important technique with you.
She explains that looking up information by name is one of the most common operations in station software. The crew rostering system looks up personnel by ID. The inventory system looks up parts by serial number. The navigation charts look up coordinates by sector name. Every system needs fast, reliable lookups, and the station's software standards recommend a specific approach for handling them.
The chief engineer shows you a reference section from the station's programming manual. It describes a data structure called a HashMap, which Java provides specifically for associating keys with values. Unlike searching through a sequence of items one by one, a HashMap allows you to store data with a key and retrieve it directly by that key. The manual explains that this is exactly what's needed when you want to ask "give me the data for this specific name" rather than "search through everything until you find this name."
She suggests you rewrite your status board program using a HashMap to store the subsystem data. Instead of keeping separate parallel structures that you search through, you'll create a HashMap where the subsystem name is the key, and the associated data is the value. When a crew member asks about "Navigation," your program can retrieve that subsystem's information directly.
The status file format remains the same:
ReactorCooling 42% NORMAL 35% 58% 35% 127 14:23
PowerDistribution 119V NORMAL 115V 124V 117V 134 14:23
LifeSupport 198000ppm NORMAL 195000ppm 205000ppm 195000ppm 128 14:23
Navigation 0.02deg WARNING 0.00deg 0.08deg 0.05deg 131 14:23
ThermalRegulation 18C NORMAL 16C 22C 15C 129 14:23
WasteRecycling 87% NORMAL 82% 95% 80% 126 14:23
CommArray 94% NORMAL 89% 98% 85% 133 14:23
DockingClamps 3201kPa NORMAL 3150kPa 3280kPa 3100kPa 130 14:23
Continue to focus on the first three fields: subsystem name, current reading, and status.
Your program should read this file and store the data in a HashMap. Since each subsystem has both a reading and a status, you'll need to decide how to store these related pieces of information. For now, you might use two HashMaps—one mapping subsystem names to readings, and another mapping names to statuses. This keeps the same functionality as before but uses HashMap's lookup capabilities.
The program's behavior should remain identical to Task 2:
=== Station Status Summary ===
ReactorCooling: 42% [NORMAL]
PowerDistribution: 119V [NORMAL]
LifeSupport: 198000ppm [NORMAL]
Navigation: 0.02deg [WARNING]
ThermalRegulation: 18C [NORMAL]
WasteRecycling: 87% [NORMAL]
CommArray: 94% NORMAL]
DockingClamps: 3201kPa [NORMAL]
Systems checked: 8
Systems with warnings: 1
Enter subsystem name (or 'quit' to exit): Navigation
Navigation: 0.02deg [WARNING]
Enter subsystem name (or 'quit' to exit): quit
Session ended.
As you implement this, you'll notice that looking up subsystem data no longer requires writing a search loop—you simply ask the HashMap for the value associated with a given key. The chief engineer mentions that while using two HashMaps works, having multiple maps that must stay synchronized is a pattern that often leads to errors. She hints that there might be a better way to keep related data together, something you'll explore as the station's software grows more complex.