Question

2. In developing software for a game, there is a need for a mapping to ’look...

2. In developing software for a game, there is a need for a mapping to ’look up’ the team affiliation for a player, an affiliation which could change during the run-time of the game. Implement a method that does the following: (a) Create a Map data structure to hold the associations between player name (key) and team affiliation (value) (b) Add at least 5 mappings to the map (c) Print out the current roster of mappings (d) Assuming some time has passed, change some of the mappings to simulate the players changing their affiliations (e) Again, print out the current roster of mappings

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Initial Team affiliations of Player5 and Player1\n");

Map<String, String> teams = new HashMap<String, String>() {{
put("Player1", "TeamA");
put("Player2", "TeamB");
put("Player3", "TeamA");
put("Player4", "TeamC");
put("Player5", "TeamC");
}};

teams.entrySet().forEach(entry->{
System.out.println(entry.getKey() + " " + entry.getValue());  
});

System.out.println("Changing Team affiliations of Player5 and Player1\n");
teams.replace("Player5","TeamA");
teams.replace("Player1","TeamC");

teams.entrySet().forEach(entry->{
System.out.println(entry.getKey() + " " + entry.getValue());  
});

}
}

----------------------------------

Output:

Initial Team affiliations of Player5 and Player1

Player5 TeamC
Player2 TeamB
Player1 TeamA
Player4 TeamC
Player3 TeamA
Changing Team affiliations of Player5 and Player1

Player5 TeamA
Player2 TeamB
Player1 TeamC
Player4 TeamC
Player3 TeamA

Add a comment
Know the answer?
Add Answer to:
2. In developing software for a game, there is a need for a mapping to ’look...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 41 2 pts A software company is developing a new computer game. The manager wants...

    Question 41 2 pts A software company is developing a new computer game. The manager wants to know what effect the frequency at which opponents are released by the computer has on the length of time players survive in the game. A large group of playtesters is available, most of whom already have some experience playing the new game, and each is randomly allocated to play the game with a different opponent release frequency Data was collected for the variables...

  • Assignment 2 – The two player game of Poaka The game of Poaka is a dice...

    Assignment 2 – The two player game of Poaka The game of Poaka is a dice game played by two players. Each player takes turns at rolling the dice. At each turn, the player repeatedly rolls a dice until either the player rolls a 1 (in which case the player scores 0 for their turn) or the player chooses to end their turn (in which case the player scores the total of all their dice rolls). At any time during...

  • Due to your experience in designing the database for the "Legendary League" game, you have been...

    Due to your experience in designing the database for the "Legendary League" game, you have been asked to design the ER diagram for a bigger database to manage the events for the "Legendary League" eSports Oceanic Championship (OC). The requirements are as follows: Registered teams compete in the OC. Each team has a name, and a number of team members. A team also maintains a rank throughout the OC, reflecting how well it is doing in the championship. Team members...

  • can someone help me with this C++ problem write your game() function and 3+ functions that...

    can someone help me with this C++ problem write your game() function and 3+ functions that simulate the game of Jeopardy Dice according to the following game mechanics and specifications. Game Mechanics There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher. The user is always the first player and starts the game. If any player reaches 80 points or more at the end of their turn, the game...

  • 2 A Game of UNO You are to develop an interactive game of UNO between a...

    2 A Game of UNO You are to develop an interactive game of UNO between a number of players. The gameplay for UNO is described at https://www.unorules.com/. Your program should operate as follows. 2.1 Setup 1. UNO cards are represented as variables of the following type: typedef struct card_s { char suit[7]; int value; char action[15]; struct card_s *pt; } card; You are allowed to add attributes to this definition, but not to remove any. You can represent colors by...

  • Currently, the game allows players to play as many times as they wish. It does not...

    Currently, the game allows players to play as many times as they wish. It does not provide any feedback on how the players are doing, however. Modify the game so that it keeps track of the number of games played as well as the average number of guesses made per game. To implement this change, add the following list of global variables to the beginning of the script’s Main Script Logic section. Assign each variable an initial value of zero....

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • The game lets players know whether they have won, lost, or tied a particular game. Modify...

    The game lets players know whether they have won, lost, or tied a particular game. Modify the game so the players are told the number of games they have won, lost or tied since the start of game play. Implement this change by adding three variables named $wins, $lost, and $ties to the program's Main Script Logic section, assigning each an initial value of 0. Next, modify the analyze_results method by adding programming logic that increments the values of $wins,...

  • Please, I need help with program c++. This is a chutes and ladders program. The code...

    Please, I need help with program c++. This is a chutes and ladders program. The code must be a novel code to the specifications of the problem statement. Thank you very much. Assignment Overview This program will implement a variation of the game “chutes and ladders” or “snakes and ladders:” https://en.wikipedia.org/wiki/Snakes_and_Ladders#Gameplay. Just like in the original game, landing on certain squares will jump the player ahead or behind. In this case, you are trying to reach to bottom of the...

  • You will implement 2 games, the Prisoner's Dilemma, The Stag Hunt and compare their results for...

    You will implement 2 games, the Prisoner's Dilemma, The Stag Hunt and compare their results for your report. After you finish implementing everything else, you will only need to change one function to make it a prisoner's dilemma or a stag hunt game 1) main.cpp: This is the driver program that sets up the game and plays it. This is where you will call functions to print the statistics. The required statistics is percentage of players using strategy 1 (cooperate...

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
ADVERTISEMENT
ADVERTISEMENT