You are to write a program (name it RoundOfGolf.java) that will create an array of 18 instances of the class GolfHole.
YOU MUST ADD A TOSTRING METHOD TO GolfHole.
This is what i have so far
public class GolfHole{//instance variablesprivate int number;private int par;private int handicap;private int score;private int distance;private String description;//default constructorpublic GolfHole(){number = 0;par = 0;handicap = 0;score = 0;distance = 0;description = "Not yet assigned";}//end default constructor//non-default constructorGolfHole(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//getterspublic int getNumber(){return number;}//end getterpublic int getPar(){return par;}//end getterpublic int getHandicap(){return handicap;}//end getterpublic int getScore(){return score;}//end getterpublic int getDistance(){return distance;}//end getterpublic String getDescription(){return description;}//end getter//setterspublic 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 ifnumber = numberPassed;}//end setterpublic 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 ifpar = parPassed;}//end getterpublic 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 ifhandicap = handicapPassed;}//end setterpublic 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 ifscore = scorePassed;}//end getterpublic 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 ifdistance = distancePassed;}//end setterpublic void setDescription(String descriptionPassed){description = descriptionPassed;}//end setter
}
import java.util.Scanner;public class RoundOfGolf{public static void main(String[] args)throws Exception {//public static final int par = 18;Scanner keyboard = new Scanner(System.in);GolfHole method = new GolfHole();int totalScore = 0;String description;int score = 0;int number;char again = 'y';String line = "";int menuSelect = 18;int parTotal = 0;boolean done = false;int []distance = new int[]{344,334,116,268,329,469,314,134,396,373,309,455,128,312,315,102,271,427};int []GolfHole = new int[18];int[]handicap = new int[]{4,2,18,16,12,8,10,14,6,5,11,7,15,9,1,17,13,3};int[] par = new int[]{4,4,3,4,4,5,4,3,5,4,4,5,3,4,4,3,4,5};int aces= 0, dEagle = 0,eagle =0,above = 0,below = 0,birdies =0,tpar =0,bogeys =0,even = 0, dBogeys =0,tBogeys =0;for(number = 0; number < 3 ; number++)//for(number = 0; number <=3; ++number){System.out.println("Please Enter your score for hole number " + (number));score = keyboard.nextInt();totalScore = totalScore + score;if(par[number] - score == 0){tpar++;}else if(par[number] - score == 1){bogeys++;above++;}else if(par[number] - score == 2){dBogeys++;above++;}else if(par[number] - score == 3){tBogeys++;above++;}else if(par[number] - score == -1){birdies++;below++;}else if(par[number] - score == -2){eagle++;below++;}else if(par[number] - score == -3){dEagle++;below++;}else if (score == 1){aces++;below++;}}//end for loopwhile(again == 'y'){System.out.println();menuSelect();menuSelect = keyboard.nextInt();switch (menuSelect) {case 1:System.out.println("\nYour total score is " + totalScore);break;case 2:System.out.println("Your total stroke above par is " + above);break;case 3:System.out.println("Your total stroke below par is " + below );break;case 4:System.out.println("Your total number of aces is " + aces);break;case 5:System.out.println("Your total number of double eagle is " + dEagle);break;case 6:System.out.println("Your total number of eagle is " + eagle);break;case 7:System.out.println("Your total number of birdies is " + birdies);break;case 8:System.out.println("Your total number of pars is " + tpar);break;case 9:System.out.println("Your total number of bogeys is " + bogeys);break;case 10:System.out.println("Your total number of double bogeys is " + dBogeys);break;case 11:System.out.println("Your total number of triple bogeys is " + tBogeys);break;case 12:System.out.println("Here is the information on the holes you score aces on ");System.out.println("The handicap for hole " + number + " is " + handicap[score] + " ");System.out.println("The distance for hole " + number + " is " + distance[score] + " ");System.out.println();break;case 13:System.out.println("You scored double eagle on these holes");break;case 14:System.out.println("You scored birdies on these holes");break;case 15:System.out.println("You scored pars on these holes");break;case 16:System.out.println("You scored bogeys on these holes");break;case 17:System.out.println("You scored double bogeys on these holes");break;case 18:System.out.println("You scored triple bogeys on these holes");break;case 19:System.out.println("Eixt the program");System.exit(0);default:System.out.println("Invalid selection");}}}//end mainpublic static void menuSelect(){System.out.println();System.out.println(" YOUR OPTIONS");System.out.println("1.Calculate and print total score");System.out.println("2.Calculate and print number of strokes above par for the round");System.out.println("3.Calculate and print number of strokes below par for the round");System.out.println("4.Calculate and print the number of aces (hole in one)");System.out.println("5.Calculate and print the number of double eagles (3 below par)");System.out.println("6.Calculate and print the number of eagles (2 below par)");System.out.println("7.Calculate and print the number of birdies (one below par)");System.out.println("8.Calculate and print the number of pars");System.out.println("9.Calculate and print the number of bogeys (one above par)");System.out.println("10.Calculate and print the number of double bogeys (two above par)");System.out.println("11.Calculate and print the number of triple bogeys (three above par)");System.out.println("12.Print the hole information for the holes on which they scored aces");System.out.println("13.Print the hole information for the holes on which they scored double eagles");System.out.println("14.Print the hole information for the holes on which they scored birdies");System.out.println("15.Print the hole information for the holes on which they scored pars");System.out.println("16.Print the hole information for the holes on which they scored bogeys");System.out.println("17.Print the hole information for the holes on which they scored double bogeys");System.out.println("18.Print the hole information for the holes on which they scored triple bogeys");System.out.println("19.Exit the program");}//end menu}//end class
Cheers ty dude