Problem

Enhance the HungerGames program in Figure. Create a Tribute class with three instance vari...

Enhance the

HungerGames
program in Figure. Create a
Tribute
class with three instance variables,
name (a String), gender (a char),
and
district (an int).
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("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

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:

• First, use

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

• Second, use

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

• Third, 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?

Figure HungerGames program

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 10
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT