CSC 221: Computer Programming I         Fall 2009

HW 4: Class Design and Implementation

For this assignment, you are to design and implement a class based on the HoopsScorer 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:

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 madeShot, missedShot, and getScore methods, making sure that you can record each type of shot and update the score accordingly. Finally, move on to the getPercentage and reset methods.

Once you have fully tested your class, you can download the file ScoreBoard.java 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 void main(String[]).


Submit your HoopsScorer.java file via the Digital Dropbox.