PlayerRoster.java:29: error: class PlayerRosterApp is public, should be declared in a file named PlayerRosterApp.java public class PlayerRosterApp { ^ 1 error
PlayerRoster.java:29: error: class PlayerRosterApp is public, should be declared in a file named PlayerRosterApp.java public class PlayerRosterApp
{ ^ 1 error
import java.util.Scanner;
class Player {
private int jerseyNumber;
private int playerRating;
public Player(int jerseyNumber, int playerRating) {
this.jerseyNumber = jerseyNumber;
this.playerRating = playerRating;
}
public int getJerseyNumber() {
return jerseyNumber;
}
public void setJerseyNumber(int jerseyNumber) {
this.jerseyNumber = jerseyNumber;
}
public int getPlayerRating() {
return playerRating;
}
public void setPlayerRating(int playerRating) {
this.playerRating = playerRating;
}
}
public class PlayerRosterApp {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int rosterSize = 5;
Player[] roster = new Player[rosterSize];
// Prompt the user to input five pairs of numbers
for (int i = 0; i < rosterSize; i++) {
System.out.print("Enter player " + (i + 1) + "'s jersey number (0 - 99): ");
int jerseyNumber = scnr.nextInt();
System.out.print("Enter player " + (i + 1) + "'s rating (1 - 9): ");
int playerRating = scnr.nextInt();
roster[i] = new Player(jerseyNumber, playerRating);
}
char option;
do {
// Implement the menu of options
System.out.println("\nMENU");
System.out.println("a - Add a player");
System.out.println("o - Output roster");
System.out.println("u - Update player rating");
System.out.println("a - Output players above a rating");
System.out.println("r - Replace player");
System.out.println("q - Quit");
System.out.print("Choose an option: ");
option = scnr.next().charAt(0);
switch (option) {
case 'o':
// Output roster
System.out.println("Roster:");
for (int i = 0; i < rosterSize; i++) {
Player player = roster[i];
System.out.println("Player " + (i + 1) + " -- Jersey Number: " + player.getJerseyNumber() + ", Rating: " + player.getPlayerRating());
}
break;
case 'u':
// Update player rating
System.out.print("Enter a player's jersey number: ");
int updateJersey = scnr.nextInt();
System.out.print("Enter a new rating for player " + updateJersey + ": ");
int newRating = scnr.nextInt();
for (int i = 0; i < rosterSize; i++) {
if (roster[i].getJerseyNumber() == updateJersey) {
roster[i].setPlayerRating(newRating);
break;
}
}
break;
case 'a':
// Output players above a rating
System.out.print("Enter a rating: ");
int ratingThreshold = scnr.nextInt();
System.out.println("Players with a rating above " + ratingThreshold + ":");
for (int i = 0; i < rosterSize; i++) {
if (roster[i].getPlayerRating() > ratingThreshold) {
System.out.println("Player " + (i + 1) + " -- Jersey Number: " + roster[i].getJerseyNumber() + ", Rating: " + roster[i].getPlayerRating());
}
}
break;
case 'r':
// Replace player
System.out.print("Enter a player's jersey number to replace: ");
int replaceJersey = scnr.nextInt();
System.out.print("Enter a new jersey number: ");
int newJersey = scnr.nextInt();
System.out.print("Enter a new rating: ");
int newPlayerRating = scnr.nextInt();
for (int i = 0; i < rosterSize; i++) {
if (roster[i].getJerseyNumber() == replaceJersey) {
roster[i].setJerseyNumber(newJersey);
roster[i].setPlayerRating(newPlayerRating);
break;
}
}
break;
case 'q':
// Quit the program
break;
default:
System.out.println("Invalid option. Please choose a valid option from the menu.");
}
} while (option != 'q');
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps