Project Requirements: 1. Develop a program that will handle a Golfer and his sco
ID: 3688825 • Letter: P
Question
Project Requirements:
1. Develop a program that will handle a Golfer and his scores. The program will be comprised of three classes: a Golfer class that will manage all the golfer's scores, a Score class and a Tester class to drive the other classes. To accomplish this task the program will use a partially filled array to store the golfer’s scores.
2. The Golfer Class
a. This is a class designed to represent a golfer including his name, home course, id number and an Array of Score Objects. The golfers scores consist of several pieces of information include the course, the par score for the course, the courses rating and course slope, date score was shot and the score. Each field is explained in detail below. Remember part of being a strong programmer is being flexible enough to learn about new domains, you don't have to be a golfer or a doctor or a banker to write application in those domains.
b. Instance Variables:
I. name - A String representing the golfer's name
II. homeCourse - A String representing the golf course where the player's handicap is keep.
III. idNum - A unique integer that identifies each golfer.
IV. scores – an Array - stores Score object that represent the golfer's scores. Set the size of the array to 10 but use numOfScores instance variable(below) to track how many Score object are actually in the array. ((NOTE: MUST USE AN ARRAY, CANNOT USE ANY OTHER TYPE OF JAVA COLLECTION OBJECT)
V. numOfScores – an int representing the number of Score Objects in the Array used in the partially filled array algorithm
c. Static Variable - int nextIDNum - starts at 1000 and is used to generate the next Golfer's IDNum
d. Methods
1. Constructor - sets name and homeCourse from parameters and uses the static variable nextIDNum to retrieve the next available ID number. Creates Array.
2. Constructor - default constructor, sets all instance field to a default value. Creates Array.
3. Accessor and mutator methods as identified in the UML Class Diagram below) NOTE Mutator method for IDNum should use the static variable nextIDNum. Mutator method should be used to set all instance fields (no accessor or mutator method for scores instance variable)
4. addScore - create a Score object from the parameters that represent the course, score, course rating, course slope, and date. Adds the newly created Score object to the Array of Scores.
5. deleteScore - delete a score from the Array based on score date, Assume only one score per day. Returns true if score found and deleted, false if not found.
6. getScore - returns a score object based on the score date. If not found returns null;
7. findScore - private method given a parameter representing the score's date, returns the Array index of a score. (Use in deleteScore and getScore). Return constant NOTFOUND if not found, NOTFOUND is set to -1;
8. toString - returns a nicely formatted string of a Golfer's information and all their scores. Use the Score toString method to assist. It should looks something like
John Smith ID number: 1234 Home Course: Bay Hill CC
Score Date Course Course Rating Course Slope
75 6/3/12 Bay Hill CC 69.5 123
77 7/23/12 AC Read 70.4 128
Golfer
-name:String
-homeCourse:String
-idNum:int
-numberOfScores:int
-static nextIDNum: int
-scores:Score[ ]
+ Golfer()
+ Golfer(String,String, int)
+ getName():String
+ getHomeCourse():String
+ getIDNum():int
+ setName(String)
+ setHomeCourse(String)
+ setIDNum()
+ addScore(String,int, double, int, String)
+ deleteScore(String):boolean
+ getScore(String):Score
- findScore(String):int
+ toString():String
3. The Score Class
a. Definitions for non-golfers ( for more definitions go to usga.org)
I. course - the specific place where golf is played, has a name such as Augusta National or St. Andrews or A,C. Read.
II. score- The number of strokes taken during a round(18 holes) of golf.
III. course rating - indicates the evaluation of the playing difficulty of a course for a scratch golfer (zero handicap) under normal course and weather conditions. It is expressed as strokes taken to one decimal place, and is based on yardage and other obstacles to the extent that they affect the scoring ability of a scratch golfer.is the starting place for the hole to be played.
IV. course slope - indicates the measurement of the relative difficulty of a course for players who are not scratch golfers. The lowest Slope Rating is 55 and the highest is 155. A golf course of standard playing difficulty has a Slope Rating of 113.
b. Instance Variables
I. courseName - a String representing the name of the course.
II. score - an int representing a 18 hole score, it must be between 40 and 200 (inclusive)
III. date - a String representing the date in format mm/dd/yy
IV. courseRating - a double representing the course rating, it must be between 60 and 80. (inclusive)
V. courseSlope - an int representing the course slope, it must be between 55 and 155 (inclusive).
NOTE: Your code should ensure all instance field are valid as described above. If not write an error message to the standard output and continues. Set field to 9999
b. Methods
I. Constructor - sets all instance fields from parameters
II. Default Constructor - sets all instance fields to a default value.
III. Access and mutator methods for all instance variables. Mutator method should be used to set all instance fields
IV. toString - returns a nicely formatted String that contains the score and its instance fields that looks something like:
75 6/3/12 Bay Hill CC 69.5 123
Score
- course:String
- score:int
- date:String
- courseRating:double
- courseSlope:int
+ Score()
+ Score(String,int,double,int)
+ getCourse():String
+ setCourse(String)
+ getScore():int
+ setScore(int)
+ getCourseRating():double
+ setCourseRating(double)
+ getSlope():int
+ setSlope(int)
+ toString():String
4. The GolferTester Class
a. This class should consists of a main method that tests all the methods in each class, either directly by calling the method from the Tester or indirectly by having another method call a method.
b. The Tester should include valid and invalid data that fully tests the application. No user input , create enough Golfer object to fully test your program.
c. Ensure you display the contents of the Golfer's array list prior to exiting.
Golfer
-name:String
-homeCourse:String
-idNum:int
-numberOfScores:int
-static nextIDNum: int
-scores:Score[ ]
+ Golfer()
+ Golfer(String,String, int)
+ getName():String
+ getHomeCourse():String
+ getIDNum():int
+ setName(String)
+ setHomeCourse(String)
+ setIDNum()
+ addScore(String,int, double, int, String)
+ deleteScore(String):boolean
+ getScore(String):Score
- findScore(String):int
+ toString():String
Explanation / Answer
Please find below the three java program for this assignment. Please let me know if any issue in understanding/compiling.
Golfer Class:-
public class Golfer{
private String name;
private String homeCourse;
private int idNum;
private Score[] scores;
private static int nextIDNum = 1000;
public Golfer(){
name = "";
homeCourse = "";
idNum = 0;
scores = new Score[0];
nextIDNum = 1000;}
public Golfer(String n, String home){
setName(n);
setHomeCourse(home);
setIDNum();
scores = new Score[100];}
public void setName(String n){
name = n;}
public String getName(){
return name;}
public void setHomeCourse(String hc){
homeCourse = hc;}
public String getHomeCourse(){
return homeCourse;}
public void setIDNum(){
idNum = nextIDNum + 1;}
public int getIDNum(){
return idNum;}
public Score addScore(String cn, double cr, int cs, String d, int sc){
Score s = new Score(cn, cr, cs, d, sc);
for (int i = 0; i < scores.length; i++){
scores[i] = (s);}
return s;}
public boolean deleteScore(String d){
String date = d;
for (int i = 0; i < scores.length; i++){
if (findScore(d) > 0){
scores[i] = null;}
return true;}
return false;}
public Score getScore(String d){
String date = d;
for (int i = 0; i < scores.length; i++){
if (findScore(d) > 0){
return scores[i];}}
return null;}
public int findScore(String d){
String date = d;
final int NOTFOUND = -1;
for (int i = 0; i < scores.length; i++){
if (scores[i].equals(date)){
return i;}}
return NOTFOUND;}
public String toString(){
Score s = new Score();
String head = getName() + " ID Number: " + getIDNum() + " Home Course: " + getHomeCourse();
String cols = "Score Date Course Course Rating Course Slope";
String score = s.toString();
return (head + " " + cols + " " + score);}
}
Score Class:-
public class Score{
private String courseName;
private int score;
private String date;
private double courseRating;
private int courseSlope;
public Score(){
courseName = "";
score = 0;
date = "";
courseRating = 0;
courseSlope = 0;}
public Score(String name, double rating, int slope, String d, int sc){
setScore(sc);
setCourseName(name);
setDate(d);
setCourseRating(rating);
setCourseSlope(slope);}
public void setCourseName(String name){
this.courseName = name;}
public String getCourseName(){
return courseName;}
public void setScore(int s){
if (s >= 40 && s <= 200){
this.score = s;}
else {
this.score = 9999;
System.out.println("ERROR");}
}
public int getScore(){
return score;}
public void setDate(String d){
this.date = d;}
public String getDate(){
return date;}
public void setCourseRating(double cr){
if (cr > 59 && cr < 81){
this.courseRating = cr;}
else {
this.courseRating = 9999;
System.out.println("ERROR");}
}
public double getCourseRating(){
return courseRating;}
public void setCourseSlope(int cs){
if (!(cs >= 55 && cs <= 155)){
this.courseSlope = 9999;
System.out.println("ERROR");}
else {
this.courseSlope = cs;}
}
public int getCourseSlope(){
return courseSlope;}
public String toString(){
String s = getScore() + " " + getDate() + " " + getCourseName() + " " + getCourseRating() + " " + getCourseSlope();
return s;}
}
GolferTester Class:-
public class GolferTester{
public static void main(String[] args){
String course1 = "test1";
String course2 = "test2";
int score1 = 55;
int score2 = 79;
int score3 = 986;
String date1 = "11/07/1981";
String date2 = "11/11/1298";
double cr1 = 65;
double cr2 = 164;
int cs1 = 55;
int cs2 = 150;
String n1 = "bob";
String n2 = "will";
String hc1 = "norman";
String hc2 = "kauai";
Score s1 = new Score(course1, cr1, cs1, date1, score1);
Golfer g1 = new Golfer(n1, hc1);
System.out.print(g1.toString());}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.