Enhance the HungerGames program. Create a Tribute class with three instance variables, name (a String), district (an

Question:

Enhance the HungerGames program. Create a Tribute class with three instance variables, name (a String), district (an int), and gender (a char). Provide this new Tribute class with a constructor to initialize its instance variables and with get methods to access them. Modify the HungerGames class by changing String deceased to Tribute deceased, making the tributes list a list of Tribute objects, and providing this additional local variable:

Map tributeMap = new HashMap<>(); 

Populate the tributes list with these objects:

Tribute("Jody", 3, 'f')

Tribute("Harve", 3, 'm',)

Tribute("Newt", 5, 'm')

Tribute("Claire", 6, 'f')

Tribute("Ruth", 10, 'f')

Then, in a for-each loop that iterates through the tributes list, use Map’s put method to put each tribute into tributeMap, using each tribute’s name as the key to the object that more completely describes that tribute. Instead of using Math.random to pick random indices, use the Collections class’s shuffle method to randomize the sequence of the tributes list. Then, in an ordinary for loop that iterates through all but the last element in the shuffled tributes list, do the following:

a) Use tributes.get

(i) to get the next object in the tributes list.

b) Use Map’s remove method to remove this object from the tributesMap map.

c) Display the three attributes of the removed object. After this for loop, in a print statement, call tributesMap.keySet() to display the keys of all remaining entries in tributesMap. Does the operation that removes an entry from the map also remove an element from the list?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: