Scenario: You have been supplied with an ascii text file containing one day’s worth of catch records. Each line in the file contains one "colon separated" catch record with three fields:
CONTESTANTS_NAME:FISH_TYPE:FISH_WEIGHT
for example
PETER:TUNNY:13.3
which indicates that a competitor called PETER caught a TUNNY weighing 13.3 kg. Note that PETER may have caught more than one fish on the day.
How would you solve this problem using java's built-in classes Tokenizer and HashMap?
Your design should provide the following analysis:
- The total weight of each type of fish caught on the day.
- The total weight of fish caught by each competitor.
- The top three competitors ranked by total catch weight.
Reason I'm posting this is that at first glance I sort of panicked knowing that any map contains just a key-value pair and had no idea how to solve this since it has three fields. What I did is have two HashMaps, first one had keys with CONTESTANT-NAME and second one keys were FISH_NAME and was able to provide the required analysis: this required a number of loops and I'm not sure if that's a good way of programming. If somebody has a better approach, please let me know. I just need the logic.