This program will store roster and rating information for a

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:

CODE GIVEN:

import java.util.Scanner;

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

Solution

import java.util.Scanner;

/**
* @author
*
*/
public class PlayerRoster {
   /**
   * @param args
   */
   public static void main(String[] args) {
       /* Type your code here. */

       Scanner scanner = null;
       try {
           scanner = new Scanner(System.in);
           int[] playerJerseyNumber = new int[5];
           int[] playerRating = new int[5];

           for (int i = 0; i < 5; i++) {
               System.out.print(\"Enter player \" + (i + 1)
                       + \"\'s jersey number: \");
               playerJerseyNumber[i] = scanner.nextInt();
               System.out.print(\"Enter player \" + (i + 1) + \"\'s rating: \");
               playerRating[i] = scanner.nextInt();

           }

           System.out.println(\"ROSTER\");

           for (int i = 0; i < 5; i++) {
               System.out.println(\"Player \" + (i + 1) + \" -- Jersey number: \"
                       + playerJerseyNumber[i] + \", Rating: \"
                       + playerRating[i]);

           }

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

               System.out.print(\"Choose an option: \");
               char choice = scanner.next().charAt(0);
               switch (choice) {
               case \'u\': {
                   System.out.print(\"Enter a jersey number: \");
                   int playerJersey = scanner.nextInt();
                   System.out.print(\"Enter a new rating for player:\");
                   int newRating = scanner.nextInt();
                   for (int i = 0; i < 5; i++) {
                       if (playerJerseyNumber[i] == playerJersey) {
                           playerRating[i] = newRating;
                           break;

                       }
                   }
               }
                   break;
               case \'a\': {
                   System.out.print(\"Enter a rating:\");
                   int aboveRating = scanner.nextInt();
                   for (int i = 0; i < 5; i++) {
                       if (playerRating[i] > aboveRating) {
                           System.out.println(\"Player \" + (i + 1)
                                   + \" -- Jersey number: \"
                                   + playerJerseyNumber[i] + \", Rating: \"
                                   + playerRating[i]);

                       }
                   }
               }

                   break;
               case \'r\': {
                   boolean flag = true;
                   do {
                       System.out.print(\"Enter a jersey number: \");
                       int playerJersey = scanner.nextInt();
                       System.out.print(\"Enter a new jersey number: \");
                       int playerNewJersey = scanner.nextInt();
                       System.out.print(\"Enter a new rating for player:\");
                       int newRating = scanner.nextInt();
                       for (int i = 0; i < 5; i++) {
                           if ((playerJerseyNumber[i] == playerJersey)) {
                               playerJerseyNumber[i] = playerNewJersey;
                               playerRating[i] = newRating;
                               flag = false;
                               break;

                           }
                       }
                       if (!flag) {
                           System.out
                                   .println(\"Error: Invalid Jersey Number...\ Try Again...\");
                       }
                   } while (flag);

               }
                   break;
               case \'o\': {
                   System.out.println(\"ROSTER\");

                   for (int i = 0; i < 5; i++) {
                       System.out.println(\"Player \" + (i + 1)
                               + \" -- Jersey number: \" + playerJerseyNumber[i]
                               + \", Rating: \" + playerRating[i]);

                   }
               }
                   break;
               case \'q\':

                   break;

               default:
                   break;
               }
               if (choice == \'q\')
                   break;
           } while (true);
       } catch (Exception e) {
           // TODO: handle exception
       }
       return;
   }
}

OUTPUT:

Enter player 1\'s jersey number: 84
Enter player 1\'s rating: 7
Enter player 2\'s jersey number: 23
Enter player 2\'s rating: 4
Enter player 3\'s jersey number: 4
Enter player 3\'s rating: 5
Enter player 4\'s jersey number: 30
Enter player 4\'s rating: 2
Enter player 5\'s jersey number: 66
Enter player 5\'s rating: 9
ROSTER
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
Player 3 -- Jersey number: 4, Rating: 5
Player 4 -- Jersey number: 30, Rating: 2
Player 5 -- Jersey number: 66, Rating: 9
MENU
u - Update player rating
a - Output players above a rating
r - Replace player
o - Output roster
q - Quit
Choose an option: o
ROSTER
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
Player 3 -- Jersey number: 4, Rating: 5
Player 4 -- Jersey number: 30, Rating: 2
Player 5 -- Jersey number: 66, Rating: 9
MENU
u - Update player rating
a - Output players above a rating
r - Replace player
o - Output roster
q - Quit
Choose an option: u
Enter a jersey number: 23
Enter a new rating for player:6
MENU
u - Update player rating
a - Output players above a rating
r - Replace player
o - Output roster
q - Quit
Choose an option: o
ROSTER
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 6
Player 3 -- Jersey number: 4, Rating: 5
Player 4 -- Jersey number: 30, Rating: 2
Player 5 -- Jersey number: 66, Rating: 9
MENU
u - Update player rating
a - Output players above a rating
r - Replace player
o - Output roster
q - Quit
Choose an option: a
Enter a rating:5
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 6
Player 5 -- Jersey number: 66, Rating: 9
MENU
u - Update player rating
a - Output players above a rating
r - Replace player
o - Output roster
q - Quit
Choose an option: r
Enter a jersey number: 4
Enter a new jersey number: 12
Enter a new rating for player:8
Error: Invalid Jersey Number...
Try Again...
MENU
u - Update player rating
a - Output players above a rating
r - Replace player
o - Output roster
q - Quit
Choose an option: q

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 i
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 i
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 i
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 i
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 i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site