Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA provide test result 1. Player Write a fully-documented class named Player which contains the players name (String), number of hits (int), and number

IN JAVA provide test result

1. Player

Write a fully-documented class named Player which contains the players name (String), number of hits (int), and number of errors (int). You should provide accessor and mutator methods for each variable as well as a default constructor. For the mutator of the hits and errors variables, you should throw an exception if the new value is less than 0. You should also provide a toString() method that returns a printable representation of the player and his statistics (hits and errors).

2. Team

Write a full-documented class named Team that stores all Player objects that belong to a particular team. The Player objects should be stored in an array. There should be a maximum of 40 Player objects allowed, a number which should be defined as a final variable. The class will be based on the following ADT specification:

public static final int MAX_PLAYERS = 40;

public Team()Brief:

Construct an instance of the Team class with no Player objects in it.

Postconditions:

This Team has been initialized to an empty list of Players.

public Object clone()Brief:

Generate a clone of this Team.

Returns:

The return value is a clone of this Team. Subsequent changes to the clone will not affect the original, nor vice versa. Note that the return value must be typecast to a Team before it can be used..

public boolean equals(Object obj)Brief:

Compare this Team to another object for equality.

Parameters:

obj - an object to which this Team is compared

Returns:

A return value of true indicates that obj refers to a Team object with the same Players in the same order as this Team. Otherwise, the return value is false. If obj is null or it is not a Team object, then the return value is false.

Note:

When comparing equality between two Player objects, you must verify that their names, hits, and errors are all the same. Using the == operator will simply check to see if the two variables refer to the same Player object, which does not take into consideration that two different Player objects can actually represent the same person. To solve this problem, you can either check that each of the properties of the two objects are the same (name, hits, errors) inside of this method, or you may simplify this process by implementing an equals method (similar to this one) for the Player class.

public int size()Brief:

Determines the number of Players currently in this Team.

Preconditions:

This Team object has been instantiated.

Returns:

The number of Players in this Team.

public void addPlayer(Player p, int position)Brief:

Adds a Player to the team at the indicated position in the lineup.

Parameters:

p - the new Player object to add to this Team.

position - the position in the lineup where the Player will be inserted .

Preconditions:

This Team object has been instantiated

1 position players_currently_in_team + 1.

The number of Player objects in this Team is less than MAX_PLAYERS.

Postconditions:

The new Player is now stored at the desired position in the Team. All Players that were originally in positions greater than or equal to position are moved back one position.

E.g. If there are 5 Players in a Team, positions 1-5, and you insert a new Player at position 4, the new Player will now be at position 4, the Player that was at position 4 will be moved to position 5, and the Player that was at position 5 will be moved to position 6).

Throws:

IllegalArgumentException - Indicates that position is not within the valid range..

FullTeamException - Indicates that there is no more room inside of the Team to store the new Player object.

Note:

Position refers to the position in the Team lineup and not the position inside the array.

Inserting a Player to position (players_currently_in_team + 1) is effectively the same as adding a Player to the end of the Team.

public void removePlayer(int position)Brief:

Removes a Player from the team at the indicated position in the lineup.

Parameters:

position - the position in the lineup from which the Player is to be removed.

Preconditions:

This Team object has been instantiated

1 position players_currently_in_team .

Postconditions:

The Player at the desired position in the Team has been removed.

All Players that were originally in positions greater than or equal to position are moved forward one position.

E.g. If there are 5 Players in a Team, positions 1-5, and you remove the Player at position 4, the Player that was at position 5 will be moved to position 4.

Throws:

IllegalArgumentException - Indicates that position is not within the valid range..

Note:

Position refers to the position in the Team lineup and not the position inside the array.

public Player getPlayer(int position)Brief:

Returns a reference to a player in the lineup at the indicated position.

Parameters:

position - the position in the lineup from which the Player is to be retrieved.

Preconditions:

This Team object has been instantiated.

Returns:

The Player from the given index.

Throws:

IllegalArgumentException - Indicates that position is not within the valid range.

Note:

Position refers to the position in the Team lineup and not the position inside the array.

public Player getLeader(String stat)

Note: If you implement this method using 'int' stat (0 or 1 indicating hits or errors), this is acceptable as well.

Brief:

Return the Player with the best value in the given statistic ("hits" or "errors").

Parameters:

stat - either "hits" or "errors".

Preconditions:

This Team object has been instantiated.

Returns:

The Player with the best stat.

Throws:

IllegalArgumentException - Indicates that indicated stat was neither "hits" nor "errors".

Note:

Remember that HIGHER hits are good, whereas LOWER errors are good.

public void printAllPlayers()Brief:

Prints a neatly formatted table of each Player in the Team on its own line with its position number as shown in the sample output.

Preconditions:

This Team object has been instantiated.

Preconditions:

A neatly formatted table of each Player in the Team on its own line with its position number has been displayed to the user.

Hint:

If your toString() method is implemented correctly as described below, you will simply need to call it and print the results to the user..

public Sring toString()Brief:

Gets the String representation of this Team object, which is a neatly formatted table of each Player in the Team on its own line with its position number as shown in the sample output.

Returns:

The String representation of this Team object.

3. TeamManager

Write a fully-documented class named TeamManager which tests the methods of the Team class and allows the user to manipulate 5 Team objects by performing operations on it.

public static final int MAX_TEAMS = 5;

public static void main(String[] args)Brief:

The main method runs a menu driven application which first creates an empty Team and then prompts the user for a menu command selecting the operation. The required information is then requested from the user based on the selected operation. Following is the list of menu options and their required information:

A) Add Player.

G) Get Player stats.

L) Get leader in a stat.

R) Remove a player.

P) Print all players.

S) Size of team.

T) Select team

C) Clone team

E) Team equals

U) Update stat.

Q) Quit.

4. FullTeamException

An Exception class which indicates a full roster.

Sample Input/Output:

// Comment in green, input in red, output in black

 Welcome to TeamManager! Team 1 is currently selected. // menu Please select an option: A) Add Player. G) Get Player stats. L) Get leader in a stat. R) Remove a player. P) Print all players. S) Size of team. T) Select team C) Clone team E) Team equals U) Update stat. Q) Quit. Select a menu option: A Enter the player's name: David Ortiz Enter the number of hits: 542 Enter the number of errors: 10 Enter the position: 1 Player added: David Ortiz - 542 hits, 10 errors // menu not shown in the sample input/output Select a menu option: A Enter the player's name: Derek Jeter Enter the number of hits: 83 Enter the number of errors: 20 Enter the position: 1 Player added: Derek Jeter - 83 hits, 20 errors // menu not shown in the sample input/output Select a menu option: P Select team index: 1 Player# Name Hits Errors ------------------------------------------------ 1 Derek Jeter 83 20 2 David Ortiz 542 10 // menu not shown in the sample input/output Select a menu option: A Enter the player's name: Albert Pujols Enter the number of hits: 222 Enter the number of errors: 15 Enter the position: 2 Player added: Albert Pujols - 222 hits, 15 errors

image text in transcribed

The UML Diagram for all the classes specified below is as follows

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

=+b) Find a 95% confidence interval for the slope and interpret it.

Answered: 1 week ago