Question: I need to create a class for a Golfer. The class should have one string attribute, name. The class should have one constructor, that accepts

I need to create a class for a Golfer.

The class should have one string attribute, name.

The class should have one constructor, that accepts the name, and throws an exception if the name is blank (If you want a challenge, throw an exception if the name contains any non-alphabetic characters)

The class should have these methods that do the following:

saveScores - argument: an array of scores for 18 holes of golf. each score is an integer. no return value. The program should also be able to create a binary file named the golfer's name plus ".dat". It should throw an exception if there are not exactly 18 elements in the array or if any element of the array is <=0. If an exception is thrown, the file should not be created.

retrieveScores - argument: none. returns the array of scores. the program reads the binary file named the golfer's name plus ".dat", populates an array with the integers in the file and return the array. Throws an exception if file doesn't exist

calcTotalScore - argument: none - return value: integer. the program reads the binary file named the golfer's name plus ".dat", calculates and returns the total of the elements in the file. Throws an exception if file doesn't exist

Create exception classes as you see fit.

Will need a test class to thoroughly test your class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!