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.
Create a file named Player.java and add the following code.
public class Player { // instance variables // constructors // accessor methods // other methods }
FREE_THROW_PERCENTAGE =
((double)FREE_THROWS_MADE / FREE_THROWS_ATTEMPTED) * 100
2POINT_FIELDGOAL_PERCENTAGE =
((double)2POINT_FIELDGOAL_MADE / 2POINT_FIELDGOAL_ATTEMPTED) * 100
3POINT_FIELDGOAL_PERCENTAGE =
((double)3POINT_FIELDGOAL_MADE / 3POINT_FIELDGOAL_ATTEMPTED) * 100
POINTS_SCORED =
FREE_THROWS_MADE + 2POINT_FIELDGOAL_MADE * 2 + 3POINT_FIELDGOAL_MADE * 3
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(); } }
Player.java
Team.java
************************ * 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