Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA CODE PLEEEASE!! This program will store roster and rating information for a

ID: 3581097 • Letter: J

Question

JAVA CODE PLEEEASE!!

This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team.

(1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int array and the ratings in another int array. Output these arrays (i.e., output the roster). (3 pts)

Ex:

(2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing. (2 pt)

Ex:

(3) Implement the "Output roster" menu option. (1 pt)

Ex:

(4) Implement the "Update player rating" menu option. Prompt the user for a player's jersey number. Prompt again for a new rating for the player, and then change that player's rating. (1 pt)

Ex:

(5) Implement the "Output players above a rating" menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value. (2 pts)

Ex:

(6) Implement the "Replace player" menu option. Prompt the user for the jersey number of the player to replace. If the player is in the roster, then prompt again for a new jersey number and rating. Update the replaced player's jersey number and rating. (2 pts)

Ex:

import java.util.Scanner;

public class PlayerRoster {
public static void main(String[] args) {
/* Type your code here. */
  
return;
}
}

Explanation / Answer


// PlayerRoster.java

import java.util.Scanner;

public class PlayerRoster
{
static Scanner scan = new Scanner(System.in);

private static void updatePlayerRating(int[] jersyNumber, int[] rating)
{
int number;
int r;
int flag = 0;

System.out.print("Enter a jersy number: ");
number = scan.nextInt();

for (int i = 0; i < 5 ; i++ )
{
if(jersyNumber[i] == number)
{
System.out.print("Enter a new rating for player: ");
r = scan.nextInt();
rating[i] = r;
flag = 1;
}
}

if(flag == 0)
System.out.println("Jersy number doesnot exist ");

}

private static void aboveRating(int[] jersyNumber, int[] rating)
{
int number;
int r;
int flag = 0;

System.out.print("Enter a rating: ");
r = scan.nextInt();

System.out.println("Above " + r);
for (int i = 0; i < 5 ; i++ )
{
if(rating[i] > r)
{
System.out.println("Player " + (i+1) + " -- Jersy Number: " + jersyNumber[i] + ", Rating: " + rating[i]);
flag = 1;
}
}

if(flag == 0)
System.out.println("No player above given rating ");

}

private static void replacePlayer(int[] jersyNumber, int[] rating)
{
int number;
int r;
int flag = 0;

System.out.print("Enter a jersy number: ");
number = scan.nextInt();

for (int i = 0; i < 5 ; i++ )
{
if(jersyNumber[i] == number)
{
System.out.print("Enter a new rating for player: ");
rating[i] = scan.nextInt();
flag = 1;
}
}

if(flag == 0)
System.out.println("Jersy number doesnot exist ");
}


private static void outputRoster(int[] jersyNumber, int[] rating)
{
System.out.println(" ROSTER");
for (int i = 0; i < 5 ; i ++ )
{
System.out.println("Player " + (i+1) + " -- Jersy Number: " + jersyNumber[i] + ", Rating: " + rating[i]);
}
}

private static void printMenu()
{
System.out.println(" MENU u - Update player rating a - Output players above a rating r - Replace player o - Output roster q - Quit Enter your choice: ");
}

public static void main(String[] args)
{
  

int[] jersyNumber = new int[5];
int[] rating = new int[5];

for (int i = 0; i < 5 ; i ++ )
{
System.out.print("Enter player " + (i+1) + "'s jersy number: ");
jersyNumber[i] = scan.nextInt();
System.out.print("Enter player " + (i+1) + "'s rating: ");
rating[i] = scan.nextInt();
}

  

while(true)
{
printMenu();
char ch = scan.nextLine().charAt(0);

switch (ch)
{

case 'u':
updatePlayerRating(jersyNumber,rating);
break;

case 'a':
updatePlayerRating(jersyNumber,rating);   
break;
  
case 'r':
replacePlayer(jersyNumber,rating);   
break;

case 'o':
outputRoster(jersyNumber,rating);   
break;

case 'q':
System.exit(0);

default:
System.out.println("Invalid input. ");
}

System.out.println();
}
}
}