For this assignment, you are to design and implement a class based on the
class from Test 1. Recall that this class kept score for a basketball team, recording 2-point and 3-point
baskets. For this assignment, you will generalize this class so that free throws (1-point baskets)
can also be recorded. In addition to calculating the shooting percentage for field goals
(2-pointers and 3-pointers combined), it will also be able to calculate shooting percentages
for each type of shot.
A skeleton for the HoopsScorer class is provided for you. It does not contain any fields and the methods are empty (or return a default value if required). You are to add appropriate fields to the class and implement the methods to carry out the designated tasks. The methods are:
madeShotrecords a made shot and updates the fields appropriately. It has a parameter that specifies which type of shot was made (either 3-point field goal, 2-point field goal, or 1-point free throw). For example, given a
scorer, the call
scorer.madeShot(3)would record a made 3-pointer, resulting in the score being increased by 3 (and the appropriate stats fields updated).
missedShotsimilarly records a missed shot. It also has a parameter that specifies the type of shot. For example, the call
scorer.missedShot(1)would record a missed free throw (and update the appropriate stats fields).
getPercentage. One has a parameter specifying the type of shot, and it returns the shooting percentage for that shot type. For example, the call
scorer.getPercentage(2)should calculate and return the percentage of 2-point field goals made. The second method, which has no parameters, returns the percentage of made field goals (2-pointers and 3-pointers, combined). In both cases, the returned percentage should be a real number between 0.0 and 100.0, rounded to a single digit to the right of the decimal place. If the team has not attempted any shots of the specified type, the call should return 0.0.
resetresets the score and all related statistics to 0, allowing for a new game to be tracked.
It is strongly recommended that you develop and test your class in stages. For example,
first specify the fields and constructor, then use BlueJ to create an object and inspect
its fields to make sure they are correct. Next, implement and test each of the
getScore methods, making sure that you can record each type of shot
and update the score accordingly. Finally, move on to the
Once you have fully tested your class, you can download the file
and add it to your BlueJ project. The
ScoreBoard class defines a graphical
user interface (GUI) that allows you to select a missed or made shot at the click of
a button, and then see the score and percentages automatically updated.
Once you have compiled this class, you can open up an interface window by
right-clicking and selecting
HoopsScorer.javafile via the Digital Dropbox.