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

I need a little bit of help on this one Need JAVA code. Thanks guys! This progra

ID: 3572737 • Letter: I

Question

I need a little bit of help on this one Need JAVA code. Thanks guys!

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

Please follow the code and comments for description :

CODE :

import java.util.Scanner; // required imports

public class soccerPlayers { // class to run the code

    public static void main(String[] args) { // driver method
        Scanner sc = new Scanner(System.in); // scanner class to get the data
        int jerseyNum[] = new int[5]; // local variables
        int rating[] = new int[5];
        for (int i = 0; i < 5; i++) { // iterate over the loop
            System.out.print(" Please Enter the " + (i + 1) + "'s jersey number (0 - 99) : "); // message
            jerseyNum[i] = sc.nextInt(); // get data
            System.out.print("Please Enter the " + (i + 1) + "'s rating (1 - 9) : "); // message
            rating[i] = sc.nextInt(); // get data
        }
        System.out.println(" ROSTER"); // message
        for (int j = 0; j < 5; j++) { // print to console
            System.out.print("Player " + (j + 1) + " -- ");
            System.out.print("Jersey Number : " + jerseyNum[j]);
            System.out.print(", Rating : " + rating[j]);
            System.out.println("");
        }

        while (true) { // display the choices
            System.out.println("");
            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 : "); // prompt
            char choice = sc.next().charAt(0); // get the data
            switch (choice) { // switch over the data
                case 'u': // for the case of updating
                    System.out.print(" Enter a jersey number : ");
                    int jNum = sc.nextInt();
                    System.out.print("Enter a new rating for player : ");
                    int newRating = sc.nextInt();
                    for (int m = 0; m < 5; m++) {
                        if (jerseyNum[m] == jNum) {
                            rating[m] = newRating; // set teh updated value
                        }
                    }
                    break;
                case 'a': // for the case of printing above the given rating
                    System.out.print(" Enter a rating : ");
                    int rat = sc.nextInt();
                    for (int n = 0; n < 5; n++) {
                        if (rating[n] > rat) {
                            System.out.print("Player " + (n + 1) + " -- "); // console print
                            System.out.print("Jersey Number : " + jerseyNum[n]);
                            System.out.print(", Rating : " + rating[n]);
                            System.out.println("");
                        }
                    }
                    break;
                case 'r': // for replacement
                    System.out.print(" Enter a jersey number : ");
                    int oJersey = sc.nextInt(); // get the data
                    System.out.print("Enter a new jersey number : ");
                    int nJersey = sc.nextInt();
                    System.out.println("Enter a rating for the new player : ");
                    int nRat = sc.nextInt();
                    for (int in = 0; in < 5; in++) {
                        if (jerseyNum[in] == oJersey) { // assign the data and check
                            jerseyNum[in] = nJersey;
                            rating[in] = nRat;
                        }
                    }
                    break;
                case 'o': // print the data
                    for (int p = 0; p < 5; p++) {
                        System.out.print("Player " + (p + 1) + " -- ");
                        System.out.print("Jersey Number : " + jerseyNum[p]);
                        System.out.print(", Rating : " + rating[p]);
                        System.out.println("");
                    }
                    break;
                case 'q': // quit the code
                    System.exit(0);
                    break;
            }
        }
    }
}


OUTPUT :


Please Enter the 1's jersey number (0 - 99) : 84
Please Enter the 1's rating (1 - 9) : 7

Please Enter the 2's jersey number (0 - 99) : 23
Please Enter the 2's rating (1 - 9) : 4

Please Enter the 3's jersey number (0 - 99) : 4
Please Enter the 3's rating (1 - 9) : 5

Please Enter the 4's jersey number (0 - 99) : 30
Please Enter the 4's rating (1 - 9) : 2

Please Enter the 5's jersey number (0 - 99) : 66
Please Enter the 5's rating (1 - 9) : 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 : 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

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 : 2

Player 1 -- Jersey Number : 84, Rating : 7
Player 2 -- Jersey Number : 23, Rating : 6
Player 3 -- Jersey Number : 4, Rating : 5
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 rating for the new player : 8

MENU
u - Update player rating
a - Output players above a rating
r - Replace player
o - Output roster
q - Quit

Choose an option : o

Player 1 -- Jersey Number : 84, Rating : 7
Player 2 -- Jersey Number : 23, Rating : 6
Player 3 -- Jersey Number : 12, Rating : 8
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 : q


Hope this is helpful.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote