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

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

ID: 3591647 • Letter: 5

Question

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

My code:

import java.util.Scanner;
public class PlayerRoster {
   public static void main(String[] args)
   {
      int jersyNumber[] = new int[5];
      int rating[] = new int[5];
      Scanner scan=new Scanner(System.in);
      for (int i = 0; i < 5; i++){
         System.out.println("Enter player " + (i+1) + "'s jersey number:");
         jersyNumber[i] = scan.nextInt();
         System.out.println("Enter player " + (i+1) + "'s rating:");
         System.out.println("");
      rating[i] = scan.nextInt();
      }
      while(true)
      {System.out.println("ROSTER"); for (int i = 0; i < 5; i++){
       System.out.println("Player "+ (i+1) + " -- Jersey number: " + jersyNumber[i] + ", Rating: " + rating[i]);}
         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 = scan.next().charAt(0);
         if(choice == 'u')
         {
            System.out.print
            ("Enter a jersey number: ");
            int 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();
                  }
                  }
                  }
                  if(choice == 'a')
                  {
                     System.out.print("Enter a rating: ");
                     int rate = scan.nextInt();
                     System.out.println("ABOVE 5");
                     for (int i = 0; i < 5; i++)
                     {
                        if(rating[i] > rate)
                        System.out.println("Player "+"-- Jersey number: "+ jersyNumber[i] +", Rating: " +rating[i]);
                        }
                        }
                        if(choice == 'r'){
                           System.out.print("Enter a jersey number: ");
                           int number = scan.nextInt();
                           for (int i = 0; i < 5; i++)
                           {
                              if(jersyNumber[i] == number){
                                 System.out.print("Enter a new "+"jersey number: ");
                                 jersyNumber[i] =
                                 scan.nextInt();
                                 System.out.print("Enter a rating "+"for the new player: ");
                                 rating[i] = scan.nextInt();}
                                 }
                                 }
                        if(choice == 'o'){
                              System.out.println("ROSTER");
                              for (int i = 0; i < 5; i++){
                              System.out.println("Player "+ (i+1) + "-- Jersey number: " + jersyNumber[i] + ", Rating: " + rating[i]);
                              }
                           }
      if(choice == 'q'){
         System.out.println("");
      System.exit(0);
      System.out.println("");}
      }}}

Errors for number 6 & 7:

6: Compare output 84 7 23 4 30 2 66 9 Input ABOVE 4 Player Jersey number: 84, Rating:7 Player-Jersey number: 4, Rating: 5 Player Jersey number: 66, Rating: 9 ROSTER Player 1 - Jersey number: 84, Rating: 7 Player 2 -Jersey number: 23, Rating: 4 Player 3Jersey number: 4, Rating: 5 Player 4Jersey number: 30, Rating: 2 Player 5 --Jersey number: 66, Rating: 9 Your output ends with MENU u Update player rating aOutput players above a rating r - Replace player oOutput roster Quit Choose an option: ABOVE 4 Player 1 -- Jersey number: 84, Rating: 7 Player 3Jersey number: 4, Rating: 5 Player 5 -- Jersey number: 66, Rating : 9 MENU u - Update player rating aOutput players above a rating r - Replace player oOutput roster gQuit Expected output ends with Choose an option:

Explanation / Answer

Player.java

public class Player {


//Declaring instance variables
private int jerseyNum;
private int rating;

//Parameterized constructor
public Player(int jerseyNum, int rating) {
super();
this.jerseyNum = jerseyNum;
this.rating = rating;
}

//getters and setters
public int getJerseyNum() {
return jerseyNum;
}
public void setJerseyNum(int jerseyNum) {
this.jerseyNum = jerseyNum;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "Jersey number :" + jerseyNum + ", Rating=" + rating;
}

}

___________________

Test.java

import java.util.ArrayList;

import java.util.Scanner;

public class Test {

//Creating an ArrayList

static ArrayList < Player > arl = new ArrayList < Player > ();

public static void main(String[] args) {

//Declaring variables

char choice;

int jerseyNum, rating;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

/* This while loop continues to execute

* until the user enters a valid input choice

*/

while (true) {

//displaying the menu

System.out.println(" MENU");

System.out.println("a - Add Player");

System.out.println("d - Delete Player");

System.out.println("u - Update Player Rating");

System.out.println("r - Output Players above a rating");

System.out.println("o - Output Roster");

System.out.println("q - Quit");

//getting the choice entered by the user

System.out.print("Enter Choice :");

choice = sc.next(".").charAt(0);

//Based on the user choice the corresponding case will executed

switch (choice) {

case 'a':

{

for (int i = 0; i < 5; i++) {

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

jerseyNum = sc.nextInt();

System.out.print("Enter the player's rating :");

rating = sc.nextInt();

Player p = new Player(jerseyNum, rating);

arl.add(p);

}

continue;

}

case 'd':

{

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

jerseyNum = sc.nextInt();

int index = searchPlayer(jerseyNum);

if (index == -1) {

System.out.println("** Player not found **");

} else {

arl.remove(index);

}

continue;

}

case 'u':

{

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

jerseyNum = sc.nextInt();

int index = searchPlayer(jerseyNum);

if (index == -1) {

System.out.println("** Player not found **");

} else {

System.out.print("Enter the player's rating :");

rating = sc.nextInt();

arl.get(index).setRating(rating);

}

continue;

}

case 'r':

{

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

rating = sc.nextInt();

System.out.println("ABOVE " + rating);

for (int i = 0; i < arl.size(); i++) {

if (arl.get(i).getRating() > rating) {

System.out.println("Player" + (i + 1) + " -- " + arl.get(i).toString());

}

}

continue;

}

case 'o':

{

System.out.println("ROSTER");

for (int i = 0; i < arl.size(); i++) {

System.out.println("Player" + (i + 1) + " -- " + arl.get(i).toString());

}

continue;

}

case 'q':

{

System.out.println("** PROGRAM EXIT**");

break;

}

default:

{

System.out.println("Invalid Choice");

continue;

}

}

break;

}

}

//This method will check whether the jersey number is available in the array list or not  

private static int searchPlayer(int jerseyNum) {

for (int i = 0; i < arl.size(); i++) {

if (arl.get(i).getJerseyNum() == jerseyNum)

return i;

}

return -1;

}

}

____________________

Output:


MENU
a - Add Player
d - Delete Player
u - Update Player Rating
r - Output Players above a rating
o - Output Roster
q - Quit
Enter Choice :a
Enter a new Player's jersey number :84
Enter the player's rating :7
Enter a new Player's jersey number :23
Enter the player's rating :4
Enter a new Player's jersey number :4
Enter the player's rating :5
Enter a new Player's jersey number :30
Enter the player's rating :2
Enter a new Player's jersey number :66
Enter the player's rating :9

MENU
a - Add Player
d - Delete Player
u - Update Player Rating
r - Output Players above a rating
o - Output Roster
q - Quit
Enter Choice :o
ROSTER
Player1 -- Jersey number :84, Rating=7
Player2 -- Jersey number :23, Rating=4
Player3 -- Jersey number :4, Rating=5
Player4 -- Jersey number :30, Rating=2
Player5 -- Jersey number :66, Rating=9

MENU
a - Add Player
d - Delete Player
u - Update Player Rating
r - Output Players above a rating
o - Output Roster
q - Quit
Enter Choice :r
Enter a rating :5
ABOVE 5
Player1 -- Jersey number :84, Rating=7
Player5 -- Jersey number :66, Rating=9

MENU
a - Add Player
d - Delete Player
u - Update Player Rating
r - Output Players above a rating
o - Output Roster
q - Quit
Enter Choice :u
Enter a Player's jersey number :30
Enter the player's rating :7

MENU
a - Add Player
d - Delete Player
u - Update Player Rating
r - Output Players above a rating
o - Output Roster
q - Quit
Enter Choice :o
ROSTER
Player1 -- Jersey number :84, Rating=7
Player2 -- Jersey number :23, Rating=4
Player3 -- Jersey number :4, Rating=5
Player4 -- Jersey number :30, Rating=7
Player5 -- Jersey number :66, Rating=9

MENU
a - Add Player
d - Delete Player
u - Update Player Rating
r - Output Players above a rating
o - Output Roster
q - Quit
Enter Choice :d
Enter a Player's jersey number :4

MENU
a - Add Player
d - Delete Player
u - Update Player Rating
r - Output Players above a rating
o - Output Roster
q - Quit
Enter Choice :o
ROSTER
Player1 -- Jersey number :84, Rating=7
Player2 -- Jersey number :23, Rating=4
Player3 -- Jersey number :30, Rating=7
Player4 -- Jersey number :66, Rating=9

MENU
a - Add Player
d - Delete Player
u - Update Player Rating
r - Output Players above a rating
o - Output Roster
q - Quit
Enter Choice :q
** PROGRAM EXIT**


_____________Could you rate me well.Plz .Thank You

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