Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* Team Client * Tests information for a basketball team * Morrison * If you write your code correctly then you should not have to

image text in transcribed

image text in transcribed

/* Team Client * Tests information for a basketball team * Morrison * If you write your code correctly then you should not have to change anything * in this file. You may need to alter some of the calls to some methods, * depending on how you write them. Please highlight any lines changed. */ public class TeamClient { public static void main( String [] args ) { //first let's create an array of Players Player [] Caveliers = new Player[12]; Caveliers[0] = new Player("Armaan Franklin", "guard", 12.7, 41.7, 71.4, 39.8); Caveliers[1] = new Player("Kihei Clark", "guard", 11.6, 42.5, 77.1, 40.0); Caveliers[2] = new Player("Jayden Gardner", "forward", 11.2, 51.9, 62.3, 0.0); Caveliers[3] = new Player("Reece Beekman", "guard", 10.0, 43.9, 84.2, 43.1); Caveliers[4] = new Player("Ben Vander Plas", "forward", 7.3, 40.2, 62.9, 32.1); Caveliers[5] = new Player("Kadin Shedrick", "forward", 7.0, 69.4, 82.6, 25.0); Caveliers[6] = new Player("Isaac McKneely", "guard", 6.6, 41.8, 73.3, 43.9); Caveliers[7] = new Player("Ryan Dunn", "guard", 2.9, 51.2, 70.0, 30.8); Caveliers[8] = new Player("Francisco Caffaro", "center", 1.7, 69.2, 50, 0); Caveliers[9] = new Player("Taine Murray", "guard", 1.5, 28.6, 75, 10); Caveliers[10] = new Player("Tristan How", "forward", 1.0, 25, 25, 0); Caveliers[11] = new Player("Chase Coleman","guard", 0.8, 16.7, 33.3, 25); // now instantiate the team calling the overloaded consstructor Team cavs = new Team(Caveliers); // now let's print the team (call toString) System.out.println(cavs); // instantiate identical object Team cavs2 = new Team( Caveliers); // calling accessors Player [ ] xx = cavs2.getTeam(); System.out.println( "The players on cavs2 are: "); for (int i = 0; i

Caveliers[0].setName("Ralph Sampson"); Caveliers[0].setPosition("center"); Team cavs3 = new Team(Caveliers); // call toString System.out.println( " cavs3: " + cavs3 ); // test equals again if ( cavs.equals( cavs3 ) ) System.out.println( "Objects are equal (WRONG)" ); else System.out.println( "Objects are not equal (This is correct)" ); System.out.println(); // find team FG percentage System.out.println( " cavs FG averages:" ); System.out.println( cavs.FGAverage()); System.out.println( ); System.out.println(); // number of centers? int x = (cavs3.positionCount("CENTER")); System.out.println( "cavs3 have " + x + " centers (should be 2)"); System.out.println(); // test sort System.out.println("Caveliers sorted by free throw pt %, descending"); Player [ ] sort = cavs.sort(); for (int i = 0; i Sports fans everywhere like to keep track of statistics - how the individual players are performing. Here at UVA, the men's basketball team is doing pretty well this year - they have been consistently ranked in the top 10! The goal of this homework is to write two classes in Java - one to represent a basketball player and another to represent the basketball team. You do not need to understand the sport of basketball to complete the assignment. 2 Player Class You need to design and implement a basketball player class Player to encapsulate the concept of a basketball player. The player has the following attributes (note that you will need to give them real Java names): - name : String - this is the first and last name of the player - position : String - this can be one of three values, "center", "guard" or "forvard", case insensitive - points per game : double - average points per game scored by this player - field goal percentage : double - number of shots made divided by number of shots attempted in all games - 3 point percentage : double - number of 3 point shots made divided by number of 3 point shots attempted in all games - free throw percentage : double - number of free throws made divided by number of free throws attempted in all games You will need to determine the necessary methods (constructor(s), accessors, mutators, manipulators, toString, equals) required for this class. We will explicitly test the following in the auto-tester: - no argument constructor - constructor with the following arguments, in this order: (name : String, position : String, points_per_game : double, field_goal_percentage : double, free_throw_percentage : double, 3_pt_percentage : double) - setName(String) - getName() : String - setPosition(String) - getposition() : String - tostring() : String which should print all the information about a player on a single line You should implement this class first and write JUnit tests to ensure the class works as expected before moving on to the Team class. You should have this working no later than Saturday of this week. 3 Team Class You need to design and implement a basketball team class Team to encapsulate the concept of a basketball team, which is a collection of players. The collection of Players should be stored as an array. For this class you should have the following methods: - A constructor taking an array of Player objects as its only parameter and assigning that array to the array data member of the class (named team), its only instance variable. Remember your deep and shallow copies here. - Accessor, mutator, and equals methods. Remember your deep and shallow copies here. - toString method. The output should print each player, their position, and associated statistics on a single line. - A method (FGAverage) returning the overall field goal average of the team. This is calculated by finding the average of all the field goal percentages of all team members. - A method (positionCount) that counts the number of players on the team at a certain position. It takes one parameter (a String) that represents a position on the team. The method should count the number of players on the team that play that position and return the count. If no players on the team match the position, a 0 should be returned. The comparisons should be case insensitive. This method does not need to validate that the input parameter is one of the three legal positions for basketball. - A method (sort) returning the array of Player objects sorted in descending order using the free throw percentage as the sorting key. Remember your deep and shallow copies here. - A method (onTeam) checking if a certain person (String input parameter to the method representing the player's name) is on the team, based on the name of that person. If the person is on the team, the method returns true; otherwise, it returns false. - A method (best 3pt ) that returns the Player that has the best 3 point percentage on the team. Here is a UML diagram of the Team class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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