write a java program (name it RoundOfGolf.java) that will create an array of 18
ID: 3545302 • Letter: W
Question
write a java program (name it RoundOfGolf.java) that will create an array of 18 instances of the class GolfHole. Use the information from the score card of Olde Scotland Links (http://oldescotlandlinks.com/course/) to populate the instances with the appropriate information (use the distance from the black tees). YOU MUST ADD A TOSTRING METHOD TO GolfHole.java.
Allow the user to enter the score from their round. Present to the user a menu that will allow the user to select to:
public class GolfHole
{
//instance variables
private int number;
private int par;
private int handicap;
private int score;
private int distance;
private String description;
//default constructor
public GolfHole()
{
number = 0;
par = 0;
handicap = 0;
score = 0;
distance = 0;
description = "Not yet assigned";
}//end default constructor
//non-default constructor
GolfHole(int numberPassed, int parPassed, int handicapPassed,
int scorePassed, int distancePassed, String descriptionPassed)
{
number = numberPassed;
par = parPassed;
handicap = handicapPassed;
score = scorePassed;
distance = distancePassed;
description = descriptionPassed;
}//end non-default constructor
//getters
public int getNumber()
{
return number;
}//end getter
public int getPar()
{
return par;
}//end getter
public int getHandicap()
{
return handicap;
}//end getter
public int getScore()
{
return score;
}//end getter
public int getDistance()
{
return distance;
}//end getter
public String getDescription()
{
return description;
}//end getter
//setters
public void setNumber(int numberPassed)
{
if(numberPassed < 1 || numberPassed > 18)
{
System.out.println("Invalid input hole number must be 1 - 18 inclusive.");
System.out.println("Hole number will be set to 0");
numberPassed = 0;
}//end if
number = numberPassed;
}//end setter
public void setPar(int parPassed)
{
if(parPassed < 1 || parPassed > 5)
{
System.out.println("Invalid input par must be 1 - 5 inclusive.");
System.out.println("Par will be set to 0");
parPassed = 0;
}//end if
par = parPassed;
}//end getter
public void setHandicap(int handicapPassed)
{
if(handicapPassed < 1 || handicapPassed > 40)
{
System.out.println("Invalid handicap must be 1 - 40 inclusive.");
System.out.println("Handicap will be set to 0");
handicapPassed = 0;
}//end if
handicap = handicapPassed;
}//end setter
public void setScore(int scorePassed)
{
if(scorePassed < 1 || scorePassed > 8)
{
System.out.println("Invalid score must be 1 - 8 inclusive.");
System.out.println("Score will be set to 8");
scorePassed = 8;
}//end if
score = scorePassed;
}//end getter
public void setDistance(int distancePassed)
{
if(distancePassed < 1)
{
System.out.println("Invalid distance must be positive.");
System.out.println("Distance will be set to 0");
distancePassed = 8;
}//end if
distance = distancePassed;
}//end setter
public void setDescription(String descriptionPassed)
{
description = descriptionPassed;
}//end setter
}//end class
Explanation / Answer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.