Enhance the
HungerGamesprogram in Figure. Create a
Tributeclass with three instance variables,
name (a String), gender (a char),and
district (an int).Provide this new
Tributeclass with a constructor to initialize its instance variables and with
getmethods to access them. Modify the
HungerGamesclass by changing
String deceased to Tribute deceased,making the
tributeslist a list of
Tributeobjects, and providing this additional local variable:
MaptributeMap = new HashMap<>();
Populate the
tributeslist with these objects:
Tribute("Cato", 'm', 2)Tribute("Katniss", 'f', 12)Tribute("Peeta", 'm', 12)Tribute("Rue", 'f', 11)Tribute("Finnick", 'm', 4)Then, in a for-each loop that iterates through the
tributeslist, use
Map’s putmethod 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.randomto pick random indices, use the
Collectionsclass’s
shufflemethod to randomize the sequence of the
tributeslist. Then, in an ordinary
forloop that iterates through all but the last element in the shuffled
tributeslist, do the following:
• First, use
tributes.get(i)to get the next object in the
tributeslist.
• Second, use
Map’s removemethod to remove this object from the
tributesMapmap.
• Third, display the three attributes of the removed object. After this
forloop, 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?
Figure HungerGames program

We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.