Question: A HashMap holds the points scored (value) for each player (key) in game 1. A similar HashMap holds the points scored for each player in

 A HashMap holds the points scored (value) for each player (key)

A HashMap holds the points scored (value) for each player (key) in game 1. A similar HashMap holds the points scored for each player in game 2. For example: HashMap(); game1.put("Chen", 4); game1.put("Jack", 9); game1.put("Reece", 4); game1.put("Steve", 6); game1.put("Michael", 6); HashMap game2 = new HashMap(); game2.put("Chen", 8); game2.put("John", 4); game2.put("Steve", 2); game2.put("Michael", 3); Do the following: Create a package named, "prob2" and a class named, "Games". Write a method named getTotals that accepts two HashMaps as described above and returns a TreeMap of all the players that played in both games and the total number of points they got. For the example above, the result is: Key=Chen, Value=12 Key=Michael, Value=9 Key=Steve, Value=8 Write a main method with the maps above, call the method getTotals, and use for-each loop to print out all the entries in the resulting TreeMap as shown above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!