ITEC 120
HW6: GolferScore (100 pts)

Academic Integrity

Be reminded that this homework assignment must be your own work.

Objectives

You will be able to write a class representing an object and a driver which instantiates several of those objects and tests the methods of the class.

Assignment

Develop a class named GolferScore and a driver to test it.

The GolferScore class will represent a particular golfer's score on an 18-hole golf course.

About scoring golf

Here's what you need to know about golf to do this assignment: There are 18 holes on a golf course. A score on any given hole is how many times the golfer has to hit the ball to get it into the hole. Each hole has a par, which is the number of strokes (hits) a first-class player should normally require for a particular hole. Golfers compare their score to par - for a particular hole, for a whole course, or for the holes they have played so far. Under par is a very good score. Par is a good score, and over par is not as good.

Suppose par for a given hole is 4. If a golfer hits the ball into the hole in 3 strokes, he completed the hole "under par". Completing a hole in one under par has a special name: a birdie.

A bogey is another special golf term; it means completing a hole in one over par.

Typical pars for a standard hole of golf are 3, 4, or 5. Typical par for an entire 18 hole course might be 69, 70, 71, 72, or 73.

Develop your class

DOWNLOAD: GolferScore.java and GolfDrv.java.

Follow the comments in the files that will guide you.

Practice iterative development

Get something to run as soon as possible, then add to it, continuing to run as you go. It's much easiser to get a small piece of code debugged and running than it is to type for hours before you try to compile.

First: Put the instance data in GolferScore, and write the constructor.

Second: Write a toString method for GolferScore. It doesn't need to be complete yet - you can add to it later.

Third: Create an instance of a GolferScore in GolfDrv and print it out.

You can't tell what your code is doing until you can print something out and see what is going on. Now you are ready to work on your other methods and make refinements to your existing code.

Testing your class

Use GolfDrv to create a GolferScore object and test ALL of your methods. This driver should NOT be interactive: simply hard code method calls and printlns in this driver. You do not need to write pass/fail tests, but you DO need to test all your methods and visually inspect the output to make sure everything is working the way it should.

Some sample output

When a new GolferScore object is created, every hole has a par, and the score for every hole is zero. Scores will be "entered" using the setScore method.

Here's an example of a nicely formatted String (as returned by the toString method). This course has not yet been completed. Notice that the totals of the score and the pars are ONLY for the holes that have been played. Also, a comparison has been made: "7 under par" is how this golfer is doing for holes 1 through 14.

Patrick McDuffer's score on Whack-a-doodle Fairways
  Hole:  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18   Total
  Par:   3  4  4  4  3  4  4  3  4  5  4  4  5  4  3  5  4  5     55
  Score: 5  5  3  3  5  2  2  3  4  4  2  2  6  2  -  -  -  -     48  7 under Par
 

Here's how that String might look after the course has been completed:

 Patrick McDuffer's score on Whack-a-doodle Fairways
  Hole:  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18  Total
  Par:   3  4  4  4  3  4  4  3  4  5  4  4  5  4  3  5  4  5    72
  Score: 5  5  3  3  5  2  2  3  4  4  2  2  6  2  6  6  3  5    68  4 under Par

Grading

Here's how your project will be graded: HW6GradingWorksheet.pdf

Submit Your Assignment

Submit TWO files!

Submit your GolferScore.java and your GolfDrv.java files to the HW6 Assignment dropbox on D2L.