CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2011
    Posts
    4

    Help with code output please!!

    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 my two classes right now. And I am trying to figure out how to get the 5 outputs. Know as you will se in the second class i am changing this code to work for this problem because i used it for a similar problem earlier. Thanks!
    client:

    Code:

    /*
    * Bradley Sanchez
    * 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).useDelimiter( ",|\n" );
    //process the data
    for(int holes = 1; holes <= 9; holes++)
    {
    counter++;
    parTotal += parValue;
    totalA += playerA;
    totalB += playerB;

    //obtained data
    System.out.println("Please enter par, scoreA, scoreB --> ");
    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);
    }
    }

    }

    This is the second class:
    Code:

    /*
    * Bradley Sanchez
    * 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";

    }

    }

    So i need to change this to get my five outputs and i am not really sure of how to do that. Thanks!

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Help with code output please!!

    What does the program output now?

    Please edit your post and wrap the code in code tags: [/code] at the end and [code] at the start
    Last edited by Norm; October 1st, 2011 at 06:23 PM.
    Norm

  3. #3
    Join Date
    Oct 2011
    Posts
    4

    Re: Help with code output please!!

    its not outputting anything.

  4. #4
    Join Date
    Oct 2011
    Posts
    4

    Re: Help with code output please!!

    Quote Originally Posted by Norm View Post
    What does the program output now?

    Please edit your post and wrap the code in code tags: [code/] at the end and [code] at the start
    this is my new client
    [code]/*
    * Bradley Sanchez
    * 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, playerA = 0, playerB = 0, aScore = 0, bScore = 0;
    boolean aWon = false;
    myGolfScore = new GolfScore();
    String pattern = ",|" + System.getProperty( "line.separator" );
    Scanner kbd = new Scanner(System.in).useDelimiter( pattern );
    //process the data
    for(int holes = 1; holes <= 9; holes++)
    {
    //obtained data
    System.out.println("Please enter par, scoreA, scoreB --> ");
    parValue = kbd.nextInt();
    playerA = kbd.nextInt();
    playerB = kbd.nextInt();

    // Tally the course par
    myGolfScore.tallyPar( parValue );

    // Tally score for each player
    myGolfScore.tallyAScores( playerA );
    myGolfScore.tallyBScores( playerB );
    }

    myGolfScore.outputResults();
    }
    }
    [code/]
    here is golf score i changed it
    [code]
    /*
    * Bradley Sanchez
    * This class maintains par, score, and total
    * 9/26/11
    * PD:4B CS2
    */

    public class GolfScore
    {
    //private data
    private int parValue, aScore, bScore;

    public void tallyAScores(int a)
    {
    aScore += a;
    }

    public void tallyBScores(int b )
    {
    bScore += b;
    }

    public void tallyPar(int p)
    {
    parValue += p;
    }
    }
    [code/]

  5. #5
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Help with code output please!!

    There are a lot of calls to the println method.
    Are you saying that none of them are executing? Nothing is printed on the screen???

    You need to add some more println statements to show where the program is executing and to show the values of variables as the program executes.

    Whoops!!! I gave you the wrong ending code tag. It should be: [/code]
    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured