Java program help please! The volleyball coach at Verde Valley
High School would like some help managing her team. She would like
a program to help her identify the best players. She has team
rosters stored in text files that contain the names of her players
(first name, then last name separated by a space), and their stats
as attacks per set (a double) followed by blocks per set (a
double). Higher stat scores are better. Each data field is
separated by a space. For example, one line in a roster file would
look like:
Gabrielle Reece 4.57 1.79
The coach would like the program to do the following:
Present a menu with the following options:
1. Open a roster file
2. List all players
3. List top attackers
4. List top blockers
5. Add a player
6. Change a player's stats
7. Count players
8. Quit program
When the user chooses 1 to open a
roster file, then the program will ask for the filename of a roster
file, then open and read the data from that file into
an ArrayList.
When the user chooses 2 to list all
players, then the program will list the names and stats of all
player players.
When the user chooses 3 to list top
attackers, then the program will determine and list the names and
stats of the players with the top 2 attack stats.
When the user chooses 4 to list top
blockers, then the program will determine and list the names and
stats of the players with the top 2 stats for blocks.
When the user chooses 5 to add a
player, then the program will prompt the user to enter the new
player's name (first and last), attack stat (double), and block
stat (double). The program should collect this information from the
user, and then instantiate a new Player object with the given name
and stats, and add that Player to the roster.
When the user chooses 6 to change a
player's stats, then the program will prompt the user to enter the
player's name (first and last). If there is a player on the roster
with the given name, then the program will collect the new attack
stat score (double), and block stat score (double), and will update
the stat values for this player.
When the user chooses 7 to count
players, then the program will display the number of players on the
current roster.
When the user chooses 8 the program
will end.
The Main class has already been designed and written
for this program. Carefully review the code in
the Main.java file and be sure that you
understand how it works.
Your task is to implement
the Player and Roster classes.
The Player class will allow us to
instantiate Player objects that will store the important
information (name, attack stat, block stat) for a player.
The Roster class will allow us to create and manage a
roster of players - we will use
an ArrayList<Player> to store
the Player objects.
Part 1 - Implement
the Player Class
In a file named Player.java, implement the
class described below.
The Player class must have the
following private instance variables:
- a variable named name that will store
a String
- a variable named attackScore that will store
a double
- a variable named blockScore that will store
a double
The Player class must have the
following public constructor method:
- an overloaded constructor that takes three arguments. The first
argument will be a String (player's name). The second
(attack score) and third (block score) arguments will be
type double.
The Player class must have the
following public methods:
- a method named getName. This accessor method will take no
arguments. This method will return a String.
- a method named getAttackScore. This accessor method will
take no arguments. This method will return a double.
- a method named setAttackScore. This mutator method will
take one double argument. This method will not return
anything.
- a method named getBlockScore. This accessor method will
take no arguments. This method will return a double.
- a method named setBlockScore. This mutator method will
take one double argument. This method will not return
anything.
- a method named printInfo. This method will take no
arguments. This method will not return anything.
Other Details
- The overloaded constructor should initialize the
object's name, attackScore and blockScore variables
with the values passed in to the parameter variables.
- The getName accessor method should simply return the
value stored in the object's name variable.
- The getAttackScore accessor method should simply
return the value currently stored in the
object's attackScore variable.
- The setAttackScore mutator method should store the
value passed in as an argument in the
object's attackScore variable.
- The getBlockScore accessor method should simply
return the value currently stored in the
object's blockScore variable.
- The setBlockScore mutator method should store the
value passed in as an argument in the
object's blockScore variable.
- The printInfo method should print out to the console,
the name and stats for this player object. The printout should look
like this:
Rachael Adams (attack = 3.36, block = 1.93)
Part 2 - Implement
the Roster Class
In a file named Roster.java, implement the
class described below.
The Roster class must have the
following private instance variables:
- a variable named playerList that will store a
reference to an ArrayList<Player>
The Roster class must have the
following public constructor methods:
- a default constructor
- an overloaded constructor that takes one argument. This
argument will be a String.
The Roster class must have the
following public methods:
- a method named addPlayer. This method will take three
arguments. The first argument will be a String (player's
name). The second (attack score) and third (block sscore) arguments
will be double.
- a method named getPlayerCount. This method will take no
arguments. This method will return an int.
- a method named getPlayerByName. This method will take
one String argument. This method will return
a Player reference.
- a method named printTopAttackers. This method will take no
arguments. This method will not return anything.
- a method named printTopBlockers. This method will take no
arguments. This method will not return anything.
- a method named printAllPlayers. This method will take no
arguments. This method will not return anything.
Other Details
- The default constructor should instantiate a
new ArrayList object, and store a reference to this
object in the Roster's playerList instance
variable.
- The overloaded constructor should instantiate a
new ArrayList object, and store a reference to this
object in the Roster's playerList instance variable.
It should then open the roster file named in the parameter
variable. It should then read in the data from this roster file
and, for each line in the file, it should create (instantiate) a
new Player object with the player name and block and
attack scores on that line, and add this Player to
the ArrayList playerList.
- The addPlayer method should instantiate a
new Player object with the name and block and attack
scores provided in the argument values, and then add
this Player to the
roster's ArrayList<Player> object.
- The getPlayerCount method should return the number of
players currently stored in the
roster's ArrayList<Player> object.
- The getPlayerByName method should iterate through the
roster's ArrayList<Player> object and search for a
player with a name that is equal to the argument value. If such
a Player is found, then this method should return a
reference to that Player object, otherwise this method
should return null.
- The printTopBlockers method should determine the
two Player objects with the best block scores (in
descending order). It should then call
the printInfo method on
these Player objects.
- The printTopAttackers method should determine the
two Player objects with the best attack stats (in
descending order). It should then call
the printInfo method on
these Player objects.
- The printAllPlayers method should iterate through the
roster's ArrayList<Player> object and call
the printInfo method on each of
these Player objects.