I need help with using javadoc commenting. I need to finish commenting on the re
ID: 3664315 • Letter: I
Question
I need help with using javadoc commenting. I need to finish commenting on the rest of the program but I'm stuck on how to correctly do that and need the commenting I've done to be checked.
//Golfer Class
public class Golfer
{
//instance variable representing golfer's name
private String name;
//instance variable representing golf course where player's handicap is keep
private String homeCourse;
//instance varibale that identifies each golfer
private int idNum;
//instnace variable that stores golfers scores
private Score[] scores;
//instance variable that list number of scores
private int numOfScores;
//static variable that generates next golfer's IDNum
private static int nextIDNum = 1000;
//constant vatiable used if findScore isn't found
private final int NOTFOUND = -1;
//default constructor that sets all instance fields to default value
public Golfer()
{
name = "";
homeCourse = "";
idNum = 0;
scores = new Score[10];
numOfScores = 0;
nextIDNum = 1000;
}
/**Paramertized constructor that constructs Golfer with setName and setHomeCourse with aName and aHomeCourse paramter values.
@param aName
@param aHomeCourse
Uses nextIDNum to retrieve next avaliable ID number.
Creates an array for score.
*/
public Golfer(String aName, String aHomeCourse)
{
setName(aName);
setHomeCourse(aHomeCourse);
setIDNum();
numOfScores = 0;
nextIDNum++;
scores = new Score[10];
}
/**Acessor method
@return returns a "name" string
*/
public String getName()
{
return name;
}
/**Acessor method
@return returns a "homeCourse" string
*/
public String getHomeCourse()
{
return homeCourse;
}
/**Acessor method
@return returns an "idNum" integer.
*/
public int getIDNum()
{
return idNum;
}
/**Mutator method that sets name equal to aName paramter value.
@param aName
*/
public void setName(String aName)
{
name = aName;
}
/**Mutator method that sets homeCourse equal to aHomeCourse paramter value.
@param aHomeCourse
*/
public void setHomeCourse(String aHomeCourse)
{
homeCourse = aHomeCourse;
}
//Mutator method that sets idNum equal to static variable nextIDNum plus 1.
public void setIDNum()
{
idNum = nextIDNum + 1;
nextIDNum++;
}
//
public void addScore(String aCourse, int aScore, double aCourseRating, int aCourseSlope, String aDate)
{
Score scr = new Score(aCourse, aScore, aCourseRating, aCourseSlope, aDate);
scores[numOfScores] = scr;
numOfScores++;
}
public boolean deleteScore(String aDate)
{
int index = findScore(aDate);
if(index == NOTFOUND)
return false;
while(index < numOfScores - 1)
{
scores[index] = scores[index + 1];
index++;
}
scores[index] = null;
numOfScores--;
return true;
}
public Score getScore(String aDate)
{
int index = findScore(aDate);
if(index == NOTFOUND)
return null;
return scores[index];
}
private int findScore(String aDate)
{
for(int i = 0; i < numOfScores; i++)
{
if(scores[i].equals(aDate))
return i;
}
return NOTFOUND;
}
public String toString()
{
String result = "";
result = result + String.format("%-13s ID number: %-6d Home Course: %-13s ", getName(), getIDNum(), getHomeCourse());
result = result + String.format("%-13s%-16s%-18s%-16s%-13s ", "Score", "Date", "Course", "Course Rating", "Course Slope");
for(int i = 0; i < numOfScores; i++)
{
result = result + scores[i];
}
return result;
}
}
//Score class
public class Score
{
private String course;
private int score;
private double courseRating;
private int courseSlope;
private String date;
public Score()
{
course = "";
score = 0;
courseRating = 0;
courseSlope = 0;
date = "";
}
public Score(String aCourse, int aScore, double aCourseRating, int aCourseSlope, String aDate)
{
setCourse(aCourse);
setScore(aScore);
setCourseRating(aCourseRating);
setSlope(aCourseSlope);
setDate(aDate);
}
public String getCourse()
{
return course;
}
public int getScore()
{
return score;
}
public double getCourseRating()
{
return courseRating;
}
public int getSlope()
{
return courseSlope;
}
public String getDate()
{
return date;
}
public void setCourse(String aCourse)
{
course = aCourse;
}
public void setScore(int aScore)
{
if(aScore >= 40 && aScore <= 200)
score = aScore;
else
System.out.println("Invalid Score!");
}
public void setCourseRating(double aCourseRating)
{
if(aCourseRating >= 60 && aCourseRating <= 80)
courseRating = aCourseRating;
else
System.out.println("Invalid Course Rating!");
}
public void setSlope(int aCourseSlope)
{
if(aCourseSlope >= 55 && aCourseSlope <= 155)
courseSlope = aCourseSlope;
else
System.out.println("Invalid Slope!");
}
public void setDate(String aDate)
{
date = aDate;
}
public String toString()
{
return String.format("%-13d%-16s%-18s%-16.2f%-13d ", getScore(), getDate(), getCourse(), getCourseRating(), getSlope());
}
}
//GolferTester Class
public class GolferTester
{
public static void main(String[] args)
{
Golfer golfer = new Golfer("John Smith", "Bay Hill CC");
golfer.addScore("Bay Hill CC", 75, 69.5, 123, "6/3/12");
golfer.addScore("AC Read", 77, 70.4, 128, "7/23/12");
System.out.println(golfer);
}
}
Explanation / Answer
//Golfer Class
public class Golfer
{
//instance variable representing golfer's name
private String name;
//instance variable representing golf course where player's handicap is keep
private String homeCourse;
//instance varibale that identifies each golfer
private int idNum;
//instnace variable that stores golfers scores
private Score[] scores;
//instance variable that list number of scores
private int numOfScores;
//static variable that generates next golfer's IDNum
private static int nextIDNum = 1000;
//constant vatiable used if findScore isn't found
private final int NOTFOUND = -1;
//default constructor that sets all instance fields to default value
public Golfer()
{
name = "";
homeCourse = "";
idNum = 0;
scores = new Score[10];
numOfScores = 0;
nextIDNum = 1000;
}
/**Paramertized constructor that constructs Golfer with setName and setHomeCourse with aName and aHomeCourse paramter values.
@param aName
@param aHomeCourse
Uses nextIDNum to retrieve next avaliable ID number.
Creates an array for score.
*/
public Golfer(String aName, String aHomeCourse)
{
setName(aName);
setHomeCourse(aHomeCourse);
setIDNum();
numOfScores = 0;
nextIDNum++;
scores = new Score[10];
}
/**Acessor method
@return returns a "name" string
*/
public String getName()
{
return name;
}
/**Acessor method
@return returns a "homeCourse" string
*/
public String getHomeCourse()
{
return homeCourse;
}
/**Acessor method
@return returns an "idNum" integer.
*/
public int getIDNum()
{
return idNum;
}
/**Mutator method that sets name equal to aName paramter value.
@param aName
*/
public void setName(String aName)
{
name = aName;
}
/**Mutator method that sets homeCourse equal to aHomeCourse paramter value.
@param aHomeCourse
*/
public void setHomeCourse(String aHomeCourse)
{
homeCourse = aHomeCourse;
}
//Mutator method that sets idNum equal to static variable nextIDNum plus 1.
public void setIDNum()
{
idNum = nextIDNum + 1;
nextIDNum++;
}
//
public void addScore(String aCourse, int aScore, double aCourseRating, int aCourseSlope, String aDate)
{
Score scr = new Score(aCourse, aScore, aCourseRating, aCourseSlope, aDate);
scores[numOfScores] = scr;
numOfScores++;
}
public boolean deleteScore(String aDate)
{
int index = findScore(aDate);
if(index == NOTFOUND)
return false;
while(index < numOfScores - 1)
{
scores[index] = scores[index + 1];
index++;
}
scores[index] = null;
numOfScores--;
return true;
}
public Score getScore(String aDate)
{
int index = findScore(aDate);
if(index == NOTFOUND)
return null;
return scores[index];
}
private int findScore(String aDate)
{
for(int i = 0; i < numOfScores; i++)
{
if(scores[i].equals(aDate))
return i;
}
return NOTFOUND;
}
public String toString()
{
String result = "";
result = result + String.format("%-13s ID number: %-6d Home Course: %-13s ", getName(), getIDNum(), getHomeCourse());
result = result + String.format("%-13s%-16s%-18s%-16s%-13s ", "Score", "Date", "Course", "Course Rating", "Course Slope");
for(int i = 0; i < numOfScores; i++)
{
result = result + scores[i];
}
return result;
}
}
//Score class
/**
* @author Your namwe
*
*/
public class Score {
//instance variables
private String course;
private int score;
private double courseRating;
private int courseSlope;
private String date;
/**
* default constructor
*/
public Score() {
course = "";
score = 0;
courseRating = 0;
courseSlope = 0;
date = "";
}
/**
* parameterized constructor
* @param aCourse
* @param aScore
* @param aCourseRating
* @param aCourseSlope
* @param aDate
*/
public Score(String aCourse, int aScore, double aCourseRating,
int aCourseSlope, String aDate) {
setCourse(aCourse);
setScore(aScore);
setCourseRating(aCourseRating);
setSlope(aCourseSlope);
setDate(aDate);
}
/**
* getters
* @return
*/
public String getCourse() {
return course;
}
/**
* @return
*/
public int getScore() {
return score;
}
/**
* @return
*/
public double getCourseRating() {
return courseRating;
}
/**
* @return
*/
public int getSlope() {
return courseSlope;
}
/**
* @return
*/
public String getDate() {
return date;
}
/**
* @param aCourse
*/
public void setCourse(String aCourse) {
course = aCourse;
}
/**
* @param aScore
*/
public void setScore(int aScore) {
if (aScore >= 40 && aScore <= 200)
score = aScore;
else
System.out.println("Invalid Score!");
}
/**
* @param aCourseRating
*/
public void setCourseRating(double aCourseRating) {
if (aCourseRating >= 60 && aCourseRating <= 80)
courseRating = aCourseRating;
else
System.out.println("Invalid Course Rating!");
}
/**
* @param aCourseSlope
*/
public void setSlope(int aCourseSlope) {
if (aCourseSlope >= 55 && aCourseSlope <= 155)
courseSlope = aCourseSlope;
else
System.out.println("Invalid Slope!");
}
/**
* @param aDate
*/
public void setDate(String aDate) {
date = aDate;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return String.format("%-13d%-16s%-18s%-16.2f%-13d ", getScore(),
getDate(), getCourse(), getCourseRating(), getSlope());
}
}
//GolferTester Class
public class GolferTester
{
public static void main(String[] args)
{
Golfer golfer = new Golfer("John Smith", "Bay Hill CC");
golfer.addScore("Bay Hill CC", 75, 69.5, 123, "6/3/12");
golfer.addScore("AC Read", 77, 70.4, 128, "7/23/12");
System.out.println(golfer);
}
}
generate javadoc with javadoc.exe tool will get api files in html format