Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I do not know why my tester is not working. Please help! Thank you. Project Requ

ID: 3829231 • Letter: I

Question

I do not know why my tester is not working. Please help! Thank you.

Project Requirements:

We are going to 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.

The Golfer Class

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.

Instance Variables.

name - A String representing the golfer's name

homeCourse - A String representing the golf course where the player's handicap is keep.

idNum - A unique integer that identifies each golfer.

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)

numOfScores – an int representing the number of Score Objects in the Array used in the partially filled array algorithm

Static Variable - int nextIDNum - starts at 1000 and is used to generate the next Golfer's IDNum

Methods

Constructor - sets name and homeCourse from parameters and uses the static variable nextIDNum to retrieve the next available ID number. Creates Array.

Constructor - default constructor, sets all instance field to a default value. Creates Array.

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)

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.

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.

getScore - returns a score object based on the score date. If not found returns null;

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;

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

The Score ClassDefinitions for non-golfers ( for more definitions go to usga.org)

course - the specific place where golf is played, has a name such as Augusta National or St. Andrews or A,C. Read.

score- The number of strokes taken during a round(18 holes) of golf.

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.

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.

Instance Variables

courseName - a String representing the name of the course.

score - an int representing a 18 hole score, it must be between 40 and 200 (inclusive)

date - a String representing the date in format mm/dd/yy

courseRating - a double representing the course rating, it must be between 60 and 80. (inclusive)

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

Methods

Constructor - sets all instance fields from parameters

Default Constructor - sets all instance fields to a default value.

Access and mutator methods for all instance variables. Mutator method should be used to set all instance fields

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

The GolferTester Class

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.

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.

Ensure you display the contents of the Golfer's array prior to exiting.

Submission Requirements:

Your project must be submitted using the instructions below. Any submissions that do not follow the stated requirements will not be graded.

1.     You should have 5 files for this assignment:

Golfer.java The Golfer class

Score.java The Score class

GolfterTester.java A driver program for your Golfer class

Golfer.html - The javadoc file for the Golfer Class. (Do not turn in)

Score.html - The javadoc file for the Golfer Class(Do not turn in)

2. Remember to compile and run your program one last time before you submit it. If your program will not compile, the graders will not be responsible for trying to test it.

3. Follow the submission requirements posted on elearning.

Important Notes:

Projects will be graded on whether they correctly solve the problem, and whether they adhere to good programming practices.

Projects must be submitted by the time specified on the due date. Projects submitted after that time will get a grade of zero.

Please review UWFs academic conduct policy. Note that viewing another student's solution, whether in whole or in part, is considered academic dishonesty. Also note that submitting code obtained through the Internet or other sources, whether in whole or in part, is considered academic dishonesty. All programs submitted will be reviewed for evidence of academic dishonesty, and all violations will be handled accordingly.

This is what I worte for my Score

public class Score
{
   private String course;
   private int score;
   private String date;
   private double courseRating;
   private int courseSlope;
  
   public Score()
   {
      this.course = "";
      this.score = 0;
      this.date = "1/1/1900";
      this.courseRating = 0.0;
      this.courseSlope = 0;
   }
  
   public Score(String course, int score, String date, double courseRating, int courseSlope)
   {
      this.course = course;
      this.score = score;
      this. date = date;
      this.courseRating = courseRating;
      this.courseSlope = courseSlope;
   }
  
   // mutators
  
   public void setCourse(String course)
   {
      this.course = course;
   }
  
   public void setScore(int score) { }
   {
      this.score = score;  
   }
  
   public void setDate(String date) { }
   {
      this.date = date;
   }
  
   public void setCourseRating(double courseRating){}
  
   public void setCourseSlope(int courseSlope){}
  
  
  
   // accessors
   public String getCourse(){ return this.course; }
  
   public int getScore(){ return 0; }
  
   public String getDate() { return ""; }
  
   public double getCourseRating(){ return 0.0; }
  
   public int getCourseSlope() { return 0; }
  
   @Override
   public String toString()
   {
      return String.format("%d",0);
   }
  

}

This is my Golfer:


public class Golfer
{
   private static int nextIDNum = 1000;

   private final int INVALID_INDEX = -1;
   private final int SCORES_CAPACITY = 10;

   private int numOfScores;
   private String name;
   private String homeCourse;
   private int idNum;
   Score[] scores;
  
   public Golfer()
   {
      this.scores = new Score[SCORES_CAPACITY];
      this.name = "";
      this.homeCourse = "";
      this.setIdNum();
      this.numOfScores =0;
     
   }
  
   public Golfer(String name, String homeCourse)
   {
      this.scores = new Score[SCORES_CAPACITY];
      this.name = name;
      this.homeCourse = homeCourse;
      this.setIdNum();
      this.numOfScores =0;
   }
  
   // mutators
   public void setIdNum()
   {
      this.idNum = nextIDNum++;
   }
  
   private void setName(String name)
   {
      this.name = name;
   }
  
   public void setHomeCourse(String homeCourse)
   {
      this.homeCourse = homeCourse;
   }
  
   // accessors
   public int getIdNum()
   {
      return this.idNum;
   }
  
   public String getName()
   {
      return this.name;
   }
  
   public String getHomeCourse()
   {
      return this.homeCourse;
   }
  
   // findScore
   private int findScore(String date)
   {
      for(int i = 0; i < numOfScores; i++)
      {
         if(((Score)scores[i]).getDate().equals(date))
            return i;
      }
     
      return INVALID_INDEX;
   }
  
   public boolean deleteScore(String date)
   {
      int idx = findScore(date);
     
      if(idx == INVALID_INDEX)
         return false;
        
      // compare the indexed position of the score we plan to delete with the numOfScores
      if(idx == (numOfScores -1))
      {
         scores[idx] = null;
         numOfScores--;
         return true;
      }
      else if(idx < numOfScores)
      {
         for(int i = idx; i < (numOfScores - 1); i++)
            scores[i] = scores[i + 1];
        
           
         scores[numOfScores -1] = null;
         numOfScores--;
         return true;
           
      }
      else
         return false;
     
  
   }

   public Score getScore(String date)
   {
     
      int idx = findScore(date);
     
      if(idx == INVALID_INDEX)
         return null;
        
      return scores[idx];  
  
   }
  
   public boolean addScore(String course, int score, String date, double courseRating, int courseSlope)
   {
     
      if(numOfScores == SCORES_CAPACITY)
         return false;
        
      Score newScore = new Score(course, score, date, courseRating, courseSlope);
      scores[numOfScores] = newScore;
      numOfScores++;
     
      return true;
  
   }

}

I’m getting an error in my Tester, and I do not know why. I am getting :

ÏGolfterTester.java:23: error: incompatible types: double cannot be converted to String


public class GolfterTester
{
   public static void main(String[] args)
   {
      Golfer golfer = new Golfer("Tiger Woods", "Pebble Beach");
  
      golfer.addScore("Pebble Beach", 75, 69.5, 123,"6/3/2016");
  
      golfer.addScore("Lee Trevino", 77, 70.4, 128, "7/23/2016");
  
      System.out.println(golfer);
  
   }

}

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

Hi

I have modified the code and highlighted the code changes below.

GolfterTester.java


public class GolfterTester
{
public static void main(String[] args)
{
Golfer golfer = new Golfer("Tiger Woods", "Pebble Beach");
  
golfer.addScore("Pebble Beach", 75, 69.5, 123,"6/3/2016");
  
golfer.addScore("Lee Trevino", 77, 70.4, 128, "7/23/2016");
  
System.out.println(golfer);
  
}

}

Golfer.java

public class Golfer
{
private static int nextIDNum = 1000;

private final int INVALID_INDEX = -1;
private final int SCORES_CAPACITY = 10;

private int numOfScores;
private String name;
private String homeCourse;
private int idNum;
Score[] scores;
  
public Golfer()
{
this.scores = new Score[SCORES_CAPACITY];
this.name = "";
this.homeCourse = "";
this.setIdNum();
this.numOfScores =0;

}
  
public Golfer(String name, String homeCourse)
{
this.scores = new Score[SCORES_CAPACITY];
this.name = name;
this.homeCourse = homeCourse;
this.setIdNum();
this.numOfScores =0;
}
  
// mutators
public void setIdNum()
{
this.idNum = nextIDNum++;
}
  
private void setName(String name)
{
this.name = name;
}
  
public void setHomeCourse(String homeCourse)
{
this.homeCourse = homeCourse;
}
  
// accessors
public int getIdNum()
{
return this.idNum;
}
  
public String getName()
{
return this.name;
}
  
public String getHomeCourse()
{
return this.homeCourse;
}
  
// findScore
private int findScore(String date)
{
for(int i = 0; i < numOfScores; i++)
{
if(((Score)scores[i]).getDate().equals(date))
return i;
}

return INVALID_INDEX;
}
  
public boolean deleteScore(String date)
{
int idx = findScore(date);

if(idx == INVALID_INDEX)
return false;
  
// compare the indexed position of the score we plan to delete with the numOfScores
if(idx == (numOfScores -1))
{
scores[idx] = null;
numOfScores--;
return true;
}
else if(idx < numOfScores)
{
for(int i = idx; i < (numOfScores - 1); i++)
scores[i] = scores[i + 1];
  

scores[numOfScores -1] = null;
numOfScores--;
return true;

}
else
return false;

  
}

public Score getScore(String date)
{

int idx = findScore(date);

if(idx == INVALID_INDEX)
return null;
  
return scores[idx];
  
}
  
public boolean addScore(String course, int score, double courseRating, int courseSlope, String date)
{

if(numOfScores == SCORES_CAPACITY)
return false;
  
Score newScore = new Score(course, score, date, courseRating, courseSlope);
scores[numOfScores] = newScore;
numOfScores++;

return true;
  
}

}

Score.java

public class Score
{
private String course;
private int score;
private String date;
private double courseRating;
private int courseSlope;
  
public Score()
{
this.course = "";
this.score = 0;
this.date = "1/1/1900";
this.courseRating = 0.0;
this.courseSlope = 0;
}
  
public Score(String course, int score, String date, double courseRating, int courseSlope)
{
this.course = course;
this.score = score;
this. date = date;
this.courseRating = courseRating;
this.courseSlope = courseSlope;
}
  
// mutators
  
public void setCourse(String course)
{
this.course = course;
}
  
public void setScore(int score) { }
{
this.score = score;
}
  
public void setDate(String date) { }
{
this.date = date;
}
  
public void setCourseRating(double courseRating){}
  
public void setCourseSlope(int courseSlope){}
  
  
  
// accessors
public String getCourse(){ return this.course; }
  
public int getScore(){ return 0; }
  
public String getDate() { return ""; }
  
public double getCourseRating(){ return 0.0; }
  
public int getCourseSlope() { return 0; }
  
@Override
public String toString()
{
return String.format("%d",0);
}
  

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote