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

6.15 Ch 5 Program: Soccer team roster (Java) This program will store roster and

ID: 3916817 • Letter: 6

Question

6.15 Ch 5 Program: Soccer team roster (Java)

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:

Explanation / Answer

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);

int[] jersey = new int[5];

int[] rating = new int[5];

int count = 0;

char choice = 'o';

// taking input of 5 members

for(count = 0; count<5; count++)

{

System.out.printf("Enter player %d's jersey number:", count+1);

jersey[count] = keyboard.nextInt();

System.out.printf("Enter player %d's rating:", count+1);

rating[count] = keyboard.nextInt();

}

while(true)

{

if(choice == 'u')

{

System.out.print(" Enter a jersey number: ");

int jnum = keyboard.nextInt();

// finding the index of that jersey

int ind = 0;

for(ind = 0; ind < count && jersey[ind] != jnum; ind++);

// taking rating

if(jersey[ind] == jnum)

{

System.out.print("Enter a new rating: ");

rating[ind] = keyboard.nextInt();

}

}

else if(choice == 'a')

{

// taking input of rating

System.out.print(" Enter a rating: ");

int above = keyboard.nextInt();

int track = 1;

System.out.println(" ABOVE");

// printing only if the rating is above that

for(int i=0; i<count; i++)

{

if(rating[i] > above)

System.out.printf("Player %d -- Jersey number: %d, Rating: %d ",track++,jersey[i],rating[i]);

}

}

else if(choice == 'r')

{

// taking jersey number

System.out.print(" Enter a jersey number: ");

int jnum = keyboard.nextInt();

int ind = 0;

// finding the index

for(ind = 0; ind < count && jersey[ind] != jnum; ind++);

if(jersey[ind] == jnum)

{

// taking input of other rating and number and updating

System.out.print("Enter a new jersey number: ");

jersey[ind] = keyboard.nextInt();

System.out.print("Enter a rating for the new player: ");

rating[ind] = keyboard.nextInt();

}

}

else if(choice == 'o')

{

// printing the roster

System.out.println(" ROSTER");

for(int i=0; i<count; i++)

{

System.out.printf("Player %d -- Jersey number: %d, Rating: %d ",i+1,jersey[i],rating[i]);

}

}

System.out.println(" MENU u - Update player rating a - Output players above a rating r - Replace player o - Output roster q - Quit");

choice = keyboard.next().charAt(0);

if(choice == 'q')

break;

}

}

}

/* SAMPLE OUTPUT

ROSTER

Player 1 -- Jersey number: 3, Rating: 4

Player 2 -- Jersey number: 5, Rating: 2

Player 3 -- Jersey number: 8, Rating: 4

Player 4 -- Jersey number: 9, Rating: 4

Player 5 -- Jersey number: 7, Rating: 9

MENU

u - Update player rating

a - Output players above a rating

r - Replace player

o - Output roster

q - Quit

u

Enter a jersey number: 3

Enter a new rating: 6

MENU

u - Update player rating

a - Output players above a rating

r - Replace player

o - Output roster

q - Quit

o

ROSTER

Player 1 -- Jersey number: 3, Rating: 6

Player 2 -- Jersey number: 5, Rating: 2

Player 3 -- Jersey number: 8, Rating: 4

Player 4 -- Jersey number: 9, Rating: 4

Player 5 -- Jersey number: 7, Rating: 9

MENU

u - Update player rating

a - Output players above a rating

r - Replace player

o - Output roster

q - Quit

a

Enter a rating: 4

ABOVE

Player 1 -- Jersey number: 3, Rating: 6

Player 2 -- Jersey number: 7, Rating: 9

MENU

u - Update player rating

a - Output players above a rating

r - Replace player

o - Output roster

q - Quit

r

Enter a jersey number: 7

Enter a new jersey number: 6

Enter a rating for the new player: 1

MENU

u - Update player rating

a - Output players above a rating

r - Replace player

o - Output roster

q - Quit

o

ROSTER

Player 1 -- Jersey number: 3, Rating: 6

Player 2 -- Jersey number: 5, Rating: 2

Player 3 -- Jersey number: 8, Rating: 4

Player 4 -- Jersey number: 9, Rating: 4

Player 5 -- Jersey number: 6, Rating: 1

MENU

u - Update player rating

a - Output players above a rating

r - Replace player

o - Output roster

q - Quit

q

*/