Basketball

Directions

A basketball coach has asked you to write a program that he can use to calculate player stats after a game. Given the following information: free throws made, free throws attempted, 2 point field goals made, 2 point field goals attempted, 3 point field goals made, and 3 point field goals attempted, he wants the program to generate the following information: percentage of free throws made, percentage of 2 point field goals made, percentage of 3 point field goals made, and total points scored.

You decide the problem can be decomposed into the following two classes: Player and Team. The Player class stores the player's name, FT made, FT attempted, 2FG made, 2FG attempted, 3FG made, and 3FG attempted. The class also calculates the percentage of FT made, percentage of 2FG made, percentage of 3FG made, and total points scored.

The Team class is a client of the Player class. It uses an array to store up to 20 players.

Player class

Create a file named Player.java and add the following code.

public class Player
{
    // instance variables

    // constructors

    // accessor methods
	
    // other methods

}

Instance Variables

  1. Declare a variable of type String named playerName.
  2. Declare a variable of type int named fta (free throws attempted).
  3. Declare a variable of type int named ftm (free throws made).
  4. Declare a variable of type int named fg2a (2 point field goals attempted).
  5. Declare a variable of type int named fg2m (2 point field goals made).
  6. Declare a variable of type int named fg3a (3 point field goals attempted).
  7. Declare a variable of type int named fg3m (3 point field goals made).

Constructors

  1. Implement a constructor which allows a client to assign initial values to all seven instance variables.

Accessor Methods

  1. Implement an accessor method for each instance variable.

Other Methods

  1. Implement a method named getFTPercentage. This method calculates and returns the free throw percentage using the following formula:

    FREE_THROW_PERCENTAGE =
    ((double)FREE_THROWS_MADE / FREE_THROWS_ATTEMPTED) * 100
  2. Implement a method named getFG2Percentage. This method calculates and returns the 2 point field goal percentage using the following formula:

    2POINT_FIELDGOAL_PERCENTAGE =
    ((double)2POINT_FIELDGOAL_MADE / 2POINT_FIELDGOAL_ATTEMPTED) * 100
  3. Implement a method named getFG3Percentage. This method calculates and returns the 3 point field goal percentage using the following formula:

    3POINT_FIELDGOAL_PERCENTAGE =
    ((double)3POINT_FIELDGOAL_MADE / 3POINT_FIELDGOAL_ATTEMPTED) * 100
  4. Implement a method named getPointsScored. This method calculates and returns the total points scored using the following formula:

    POINTS_SCORED = 
    FREE_THROWS_MADE + 2POINT_FIELDGOAL_MADE * 2 + 3POINT_FIELDGOAL_MADE * 3

Team class

Create a file named Team.java and add the following code.

import java.util.*;

public class Team
{
    // instance variables

    // constructor


    /* This method allows a user to input up to 20 basketball players and 
     *  stores them in an array.
     */
    public void addPlayers()
    {
        Scanner keyboard = new Scanner(System.in);


    }

    /* This method displays each Player in the array 
     */
    public void printPlayers()
    {

    }

    public static void main(String[] args)
    {
        Team app = new Team();
        app.addPlayers();
        app.printPlayers();
    }
}

Instance Variables

  1. Implement any necessary instance variables.

Constructors

  1. Implement any necessary constructors.

addPlayers Method

  1. Implement the method addPlayers. This method allows a user to input up to 20 basketball players and stores them in an array.

printPlayers Method

  1. Implement the method printPlayers. This method displays each Player in the array. The information displayed includes the player's name, FT made, FT attempted, 2FG made, 2FG attempted, 3FG made, 3FG attempted, percentage of FT made, percentage of 2FG made, percentage of 3FG made, and total points scored.

Source File

Player.java

Team.java

Sample Run

************************
*      addPlayers      *
************************

Enter player name-->Michael Jordan
Enter free throws made -->5
Enter free throws attempted -->6
Enter 2 pt field goals made -->12
Enter 2 pt field goals attempted -->24
Enter 3 pt fields goals made --3
Enter 3 pt field goals attempted -->4

Enter another player [y/n]:y

Enter player name-->Magic Johnson
Enter free throws made -->1
Enter free throws attempted -->3
Enter 2 pt field goals made -->8
Enter 2 pt field goals attempted -->10
Enter 3 pt fields goals made --1
Enter 3 pt field goals attempted -->1

Enter another player [y/n]:y

Enter player name-->Dirk Nowitzki
Enter free throws made -->10
Enter free throws attempted -->10
Enter 2 pt field goals made -->15
Enter 2 pt field goals attempted -->28
Enter 3 pt fields goals made --4
Enter 3 pt field goals attempted -->5

Enter another player [y/n]:n

************************
*     printPlayers     *
************************
Name = Michael Jordan
Free Throws % = 83.33333333333334
2 pt Field Goal % = 50.0
3 pt Field Goal % = 75.0
Total Points Scored = 38

Name = Magic Johnson
Free Throws % = 33.33333333333333
2 pt Field Goal % = 80.0
3 pt Field Goal % = 100.0
Total Points Scored = 20

Name = Dirk Nowitzki
Free Throws % = 100.0
2 pt Field Goal % = 53.57142857142857
3 pt Field Goal % = 80.0
Total Points Scored = 52