# ACSL Golf Code errors

Page 1 of 1

## 2 Replies - 320 Views - Last Post: 01 October 2011 - 09:06 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=249380&amp;s=a8bac466819841bc29c5f7742feadbed&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 bhsanchez72

Reputation: 0
• Posts: 51
• Joined: 01-October 11

# ACSL Golf Code errors

Posted 01 October 2011 - 07:41 AM

PROBLEM: In the sport of golf, scoring is based upon what a normal score should be for a particular hole on a course. That normal score called “par” is based upon the length of that hole measured from the tee, the start point, to the green, the end point. For the vast majority of golf courses and for this problem par values will be either 3, 4 or 5. Golf scores can be reported in three ways. The first way is to report cumulative score. That is, the player scored a 68 after playing the standard 18 holes. The second way is to report the cumulative score in relation to par. If par for the course ( the sum of the par values of all the holes) is 72, then the score reported as 68 would be 4 under par. A score of 75 would be 3 over par. A score of 72 is reported as par. The third way is by holes won. A player wins a hole when his score is lower than his opponent’s score.

INPUT: There will be 9 input lines. Each line will contain 3 positive integers. The first integer will give the par value of each of the nine holes. The second integer will give the score for player A on the same nine holes. The third integer will give the score for player B on the those nine holes.

OUTPUT: There will be five outputs. Print the following:

1. The cumulative score for each player with the better score (the smaller number) first.
2. The score in relation to par for the better score.
3. The score in relation to par for the other player.
4. The number of holes won by the player with the better score.
5. The sum of the scores on a the hole that is the highest for all the holes played.
______________________________________________________________
INPUT:
1. 3,2,3
2. 4,5,5
3. 5,6,6
4. 4,3,4
5. 4,3,4
6. 4,4,5
7. 5,5,6
8. 3,3,3
9. 4,4,5

OUTPUT:
1. 35, 41
2. 1 under par
3. 5 over par
4. 6
5. 12

These are the two classes i have right now i just need some help getting the outputs.

Client
/*
* Client that obtains data for use by the golfer
* 9/26/11
* PD:4B CS2
*/

import java.util.Scanner;
public class ACSLGolfClient {

public static void main(String[] args)
{
//declare variables
GolfScore myGolfScore;
int parValue = 0, parTotal = 0, playerA = 0, playerB = 0, totalA = 0, totalB = 0, counter = 0, highScoreA, highScoreB, highScore, aHolesWon = 0, bHolesWon = 0;
myGolfScore = new GolfScore();
Scanner kbd = new Scanner(System.in);
//process the data
for(int holes = 1; holes <= 4; holes++)
{
counter++;
parTotal += parValue;
totalA += playerA;
totalB += playerB;

//obtained data
System.out.println("Please enter par for the hole --> ");
parValue = kbd.nextInt();
playerA = kbd.nextInt();
playerB = kbd.nextInt();

//access the class with the data
myGolfScore.tallyPar(aHolesWon);
myGolfScore.tallyScores(bHolesWon);

//output results
System.out.println(myGolfScore.outcome(aHolesWon, bHolesWon));
System.out.println(totalA);
}
totalA = myGolfScore.getScore() - myGolfScore.getpar();
if(playerA < playerB)
{
aHolesWon ++;
}
else
{
bHolesWon ++;
}

if(totalA < totalB)
{
System.out.println(totalA + " , " + totalB);
}
else
{
System.out.println(totalB + " , " + totalA);
}

highScoreA = parTotal - totalA;
highScoreB = parTotal - totalB;

if (highScoreA >= 0)
{
System.out.println(Math.abs(highScoreA) + " under par");
}
else
{
System.out.println(Math.abs(highScoreA) + " over par");
}

if (highScoreB < 0)
{
System.out.println(Math.abs(highScoreB) + " over par");
}
else
{
System.out.println(Math.abs(highScoreB) + " under par");
}

if(aHolesWon > bHolesWon)
{
System.out.println(aHolesWon);
}
else
{
System.out.println(bHolesWon);
}
}

}

second class
/*
* This class maintains par, score, and total
* 9/26/11
* PD:4B CS2
*/

public class GolfScore
{
//private data
private int par, score;

//default constructor
public GolfScore()
{
par = 0;
score = 0;
}

public void tallyPar(int p)
{
par += p;
}

public void tallyScores(int s)
{
score += s;
}

public int getpar()
{
return par;
}

public int getScore()
{
return score;
}

public String outcome(int p, int s)
{
if(p == s)
return "a score equal to par";
else if(p - s == 1)
return "birdie";
else if(p - s == 2)
return "eagle';";
else if(p + 1 == s)
return "bogey";
else
return "double bogey";

}

}

zThat is what i have and i am having trouble getting the right outputs. Thanks!

Is This A Good Question/Topic? 0

## Replies To: ACSL Golf Code errors

### #2 Ryano121

• D.I.C Lover

Reputation: 1376
• Posts: 3,015
• Joined: 30-January 11

## Re: ACSL Golf Code errors

Posted 01 October 2011 - 07:43 AM

You already have a topic open for this, please don't open duplicates.

This post has been edited by Ryano121: 01 October 2011 - 07:44 AM

### #3 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11248
• Posts: 42,313
• Joined: 27-December 08

## Re: ACSL Golf Code errors

Posted 01 October 2011 - 09:06 AM