Question: package cubacuba; import java.util. * ; import java.util.concurrent.atomic.AtomicInteger; class Player { private final AtomicInteger playerIDCounter = new AtomicInteger ( 1 ) ; String playerID; String

package cubacuba;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
class Player {
private final AtomicInteger playerIDCounter = new AtomicInteger(1);
String playerID;
String playerName;
int score;
String gameID;
Player next;
Player(String playerName, String gameID){
this.playerID = generatePlayerID();
this.playerName = playerName;
this.score =0;
this.gameID = gameID;
this.next = null;
}
private String generatePlayerID(){
return "P"+ playerIDCounter.getAndIncrement();
}
public String getPlayerID(){
return playerID;
}
public void setPlayerName(String newName){
this.playerName = newName;
}
public void setScore(int newScore){
this.score = newScore;
}
public int getScore(){
return score;
}
public String getGameID(){
return gameID;
}
}
class Game {
String gameID;
String gameName;
Player head;
Game(String gameName){
this.gameID = generateGameID(gameName);
this.gameName = gameName;
this.head = null;
}
private String generateGameID(String gameName){
return gameName.substring(0,3).toUpperCase();
}
public String getGameID(){
return gameID;
}
public void addPlayer(Player player){
player.next = head;
head = player;
}
public void removePlayer(String playerID){
if (head == null){
return;
}
if (head.getPlayerID().equals(playerID)){
head = head.next;
return;
}
Player current = head;
Player previous = null;
while (current != null && !current.getPlayerID().equals(playerID)){
previous = current;
current = current.next;
}
if (current != null){
previous.next = current.next;
}
}
public Player findPlayer(String playerID){
Player current = head;
while (current != null && !current.getPlayerID().equals(playerID)){
current = current.next;
}
return current;
}
}
public class GameScoreManagementSystem {
static List games = new ArrayList<>();
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args){
initializeGames();
char ch;
do {
printMainMenu();
ch = scanner.next().toUpperCase().charAt(0);
switch (ch){
case '1':
displayStandingsMenu();
break;
case '2':
editPlayerDataMenu();
break;
case 'X':
System.out.println("
Exiting Game Score Management System");
break;
default:
System.out.println("
Invalid entry. Please select 1,2, or X
");
}
} while (ch !='X');
}
private static void initializeGames(){
games.add(new Game("Badminton"));
games.add(new Game("Football"));
games.add(new Game("Volleyball"));
}
private static void printMainMenu(){
System.out.println("
[-------Game Score Management System-------]");
System.out.println("1- Display Standings");
System.out.println("2- Edit Player Data");
System.out.println("X - Exit");
System.out.print("Enter your choice: ");
}
private static void displayStandingsMenu(){
if (games.isEmpty()){
System.out.println("
No games available. Please add games first.");
return;
}
System.out.println("
[-----Display Standings Menu-----]");
for (int i =0; i < games.size(); i++){
System.out.println((i +1)+"-"+ games.get(i).gameName);
}
System.out.println("X - Back to Main Menu");
System.out.print("Enter your choice: ");
char gameChoice = scanner.next().toUpperCase().charAt(0);
if (gameChoice =='X'){
System.out.println("
Returning to Main Menu");
} else if (gameChoice >='1' && gameChoice <='9'){
int gameIndex = Character.getNumericValue(gameChoice)-1;
if (gameIndex >=0 && gameIndex < games.size()){
displayGameStandings(games.get(gameIndex));
} else {
System.out.println("
Invalid entry. Please select a valid game or X
");
}
} else {
System.out.println("
Invalid entry. Please select a valid game or X
");
}
}
private static void displayGameStandings(Game game){
if (game.head == null){
System.out.println("
The player list for "+ game.gameName +" is empty.
");
return;
}
Player current = game.head;

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!