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

This program will store roster and rating information for a soccer team. Coaches

ID: 3591061 • Letter: T

Question

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 players rating (1-9). Store the jersey numbers in one int array and the ratings in another int array. Output these arraylie, output the roster). (3 pts) Ex: 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: 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 1Jersey rumber: 84, Rating: 7 Player 2Jersey number: 23, Rating: 4 (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

Explanation / Answer

package org.students;

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;
}

}

_____________________

package org.students;

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());

}

}

case 'q':

{

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 :u
Enter a Player's jersey number :30
Enter the player's rating :8

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
Player4 -- Jersey number :30, Rating=8
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=8
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