COMP 110-003 Fall 2008
Program 3: Statistics
65 points
Assigned: Monday, October 13
*** Updated ***: Thursday, October 23
Due: Friday, October 31 at 2:00pm
Description
*** UNCStats.java WAS UPDATED. PLEASE REFRESH YOUR BROWSER WHEN YOU
CLICK ON UNCStats.java IN CASE YOUR BROWSER STILL HAS THE OLD FILE CACHED. ***
This program will give you practice with writing a class from scratch.
You will write a class, Statistics, that calculates basketball statistics.
I have given you the main program UNCStats.java
that will use your Statistics class. You will need to write the class Statistics
(in a separate file named Statistics.java) that includes the following:
Constructor:
- A constructor that takes two String parameters: the university's name and the basketball
team's name. This constructor should save these names in instance variables. It should
also initialize all of your other instance variables to reasonable values.
Mutator methods:
setFieldGoalsMade set2PointFieldGoalsMade will take the total
number of 2-point field goals scored as a parameter and save the data in an instance variable
setFieldGoalAttempts set2PointFieldGoalsAttempted will take the total
number of 2-point field goals attempted as a parameter and save the data in an instance variable
set3PointersMade set3PointFieldGoalsMade will take the total
number of 3-point field goals scored as a parameter and save the data in an instance variable
set3PointAttempts set3PointFieldGoalsAttempted will take the total
number of 3-point field goals attempted as a parameter and save the data in an instance variable
- setFreeThrowsMade will take the total number of free throws scored
as a parameter and save the data in an instance variable
- setFreeThrowsAttempted will take the total number of free throws attempted
as a parameter and save the data in an instance variable
Accessor methods:
- getUniversityName returns the university's name
- getTeamName returns the team's name
- getTotalPoints calculates the total number of points the team has scored
and returns the total number of points. (Remember:
field goal 2-point field goal = 2 points,
free throw = 1 point, 3-pointer 3-point field goal = 3 points)
- getFieldGoalPercent calculates and returns the percentage of field goals the team has made (Note (new):
the field goal percentage is the number of field goals made divided by the number of field goals attempted --
this includes both 2-point field goals and 3-point field goals)
- getFreeThrowPercent calculates and returns the percentage of free throws the team has made
- get3PointPercent calculates and returns the percentage of 3-pointers the team has made
You will need to determine your own private instance variables. You
should declare all your variables at the beginning of your class and initialize
them in your constructor. Once you have completed the methods, you can test
your class by compiling UNCStats.java and running the program. Your output should
look exactly like this (you should not modify UNCStats.java) (new):
UNC's Tar Heels:
scored 2641 points
have a field-goal percentage of 45.84%
have a free-throw percentage of 75.72%
have a 3-point field-goal percentage of 36.43%
How to turn in the assignment
- Name your class
Statistics
and your Java source file Statistics.java
.
- Make sure you put the standard program header at the top of your code
and modify the header appropriately.
- Follow the instructions for creating a JAR file named
yourlastname_prg3.jar
containing your Java source code.
Do NOT put UNCStats.java
in your JAR file. I will use my own UNCStats.java
.
- Send me an email with the subject line
COMP110 Program3 yourlastname
with the following attachments:
yourlastname_prg3.jar
(where yourlastname
is your last name),
which includes your Statistics.java
source file
Print a copy of your code (Statistics.java
) and hand it in at the beginning of
class on the due date.
Please let me know if you are having any problems with the assignment submission process.
Grading
- (2 points) Pledge headers, with fields changed appropriately
- (3 points) Printed copy of your
Statistics.java
code
- (8 points) Variable declarations
- (4 points) Constructor
- (48 points) 4 points for each method
You can also lose points for incorrectly handing in the assignment, not using appropriate white space,
not using conventional names for any variables you declare, and not commenting your code where appropriate.