Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

Find the rotation of = [1 0 3]T about the z axis through = /6.

Answered: 1 week ago

Question

5. Explain how ERISA protects employees pension rights.

Answered: 1 week ago

Question

8. Describe the main retirement benefits.pg 87

Answered: 1 week ago