ACSL Golf Code errors

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »

102 Replies - 2739 Views - Last Post: 02 October 2011 - 06:36 PM Rate Topic: -----

#31 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: ACSL Golf Code errors

Posted 01 October 2011 - 02:19 PM

I like that. You're focused on the goal. Now get to work.
Was This Post Helpful? 1
  • +
  • -

#32 bhsanchez72  Icon User is offline

  • D.I.C Head

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

Re: ACSL Golf Code errors

Posted 01 October 2011 - 02:33 PM

View PostGregBrannon, on 01 October 2011 - 02:19 PM, said:

I like that. You're focused on the goal. Now get to work.

Have no clue how to do it though, this is what i have been trying to figure out the whole time please help me . I have never done this before.
Was This Post Helpful? 0
  • +
  • -

#33 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: ACSL Golf Code errors

Posted 01 October 2011 - 02:41 PM

But you have to try. At a minimum, take what I told you the for loop should look like, cut and paste that into your existing ACSLGolfClient, and make up two method names for for the commented lines I left blank. Give the methods good names that describe what they do. After you've done that, copy that back at me with any questions you have, something other than "I don't have a clue." Yes, Eclipse will show you all kinds of errors, and No, the code won't run, but we'll fix that - as long as you keep trying.
Was This Post Helpful? 1
  • +
  • -

#34 bhsanchez72  Icon User is offline

  • D.I.C Head

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

Re: ACSL Golf Code errors

Posted 01 October 2011 - 02:46 PM

View PostGregBrannon, on 01 October 2011 - 02:41 PM, said:

But you have to try. At a minimum, take what I told you the for loop should look like, cut and paste that into your existing ACSLGolfClient, and make up two method names for for the commented lines I left blank. Give the methods good names that describe what they do. After you've done that, copy that back at me with any questions you have, something other than "I don't have a clue." Yes, Eclipse will show you all kinds of errors, and No, the code won't run, but we'll fix that - as long as you keep trying.

Can you make the first method and explain it then i will do the second one please.
Was This Post Helpful? 0
  • +
  • -

#35 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: ACSL Golf Code errors

Posted 01 October 2011 - 02:48 PM

Sure. I wasn't even talking about writing the methods yet, but that's a good plan. I'll write the first new method in the for loop, and you'll have the next, maybe the rest, but definitely the next. I'll help when you get into a jam.

Show me your for loop when you have it ready.
Was This Post Helpful? 1
  • +
  • -

#36 bhsanchez72  Icon User is offline

  • D.I.C Head

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

Re: ACSL Golf Code errors

Posted 01 October 2011 - 02:53 PM

View PostGregBrannon, on 01 October 2011 - 02:48 PM, said:

Sure. I wasn't even talking about writing the methods yet, but that's a good plan. I'll write the first new method in the for loop, and you'll have the next, maybe the rest, but definitely the next. I'll help when you get into a jam.

Show me your for loop when you have it ready.

Here is my recent client does that have the correct for loop or do i have to add something.

/*
 * 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();
		String pattern = ",|" + System.getProperty( "line.separator" );
		Scanner kbd = new Scanner(System.in).useDelimiter( pattern );
		//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);
		}
}
		
	}





View Postbhsanchez72, on 01 October 2011 - 02:51 PM, said:

View PostGregBrannon, on 01 October 2011 - 02:48 PM, said:

Sure. I wasn't even talking about writing the methods yet, but that's a good plan. I'll write the first new method in the for loop, and you'll have the next, maybe the rest, but definitely the next. I'll help when you get into a jam.

Show me your for loop when you have it ready.

Here is my recent client does that have the correct for loop or do i have to add something.

/*
 * 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();
		String pattern = ",|" + System.getProperty( "line.separator" );
		Scanner kbd = new Scanner(System.in).useDelimiter( pattern );
		//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);
		}
}
		
	}




And dont have to change some stuff in the other class like the string, but i am not sure how i would change the string.
Was This Post Helpful? 0
  • +
  • -

#37 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: ACSL Golf Code errors

Posted 01 October 2011 - 03:01 PM

Nice edit.

So that we're both working towards the same goal, here's what I think the ENTIRE class ACSLGolfClient should look like. Any complaints? Notice I still left two methods for you to name - that's all at this point, name them. Copy and paste this version into yours and give me the name of the first method with a red squiggly under it.

/*
 * 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;
        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.tallyAScores( playerB );
            
            // tally holes won
                                   // <name the method here
            
            // submit scores for the highest total on any hole
                                   // <name the method here
        }

        myGolfScore.outputResults();
    }
}

Was This Post Helpful? 1
  • +
  • -

#38 bhsanchez72  Icon User is offline

  • D.I.C Head

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

Re: ACSL Golf Code errors

Posted 01 October 2011 - 03:03 PM

View PostGregBrannon, on 01 October 2011 - 03:01 PM, said:

Nice edit.

So that we're both working towards the same goal, here's what I think the ENTIRE class ACSLGolfClient should look like. Any complaints? Notice I still left two methods for you to name - that's all at this point, name them. Copy and paste this version into yours and give me the name of the first method with a red squiggly under it.

/*
 * 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;
        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.tallyAScores( playerB );
            
            // tally holes won
                                   // <name the method here
            
            // submit scores for the highest total on any hole
                                   // <name the method here
        }

        myGolfScore.outputResults();
    }
}

Ok now couldnt i put the methods in the other class and then call them in the client?

This post has been edited by bhsanchez72: 01 October 2011 - 03:05 PM

Was This Post Helpful? 0
  • +
  • -

#39 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: ACSL Golf Code errors

Posted 01 October 2011 - 03:05 PM

Exactly. The methods are going to be written in the other class. That's why the ones I named already begin with myGolfScore. which is an instance of the GolfScore class.
Was This Post Helpful? 1
  • +
  • -

#40 bhsanchez72  Icon User is offline

  • D.I.C Head

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

Re: ACSL Golf Code errors

Posted 01 October 2011 - 03:09 PM

View PostGregBrannon, on 01 October 2011 - 03:05 PM, said:

Exactly. The methods are going to be written in the other class. That's why the ones I named already begin with myGolfScore. which is an instance of the GolfScore class.

Okay here is the other class is this what it should look like or can you revise it. Then we can start on the first method. Because right now i know i need two methods name tallyBScores and tallyAScores
/*
 * 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";
				
	}

}


This post has been edited by bhsanchez72: 01 October 2011 - 03:11 PM

Was This Post Helpful? 0
  • +
  • -

#41 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: ACSL Golf Code errors

Posted 01 October 2011 - 03:11 PM

Okay. I had that. Now look at the other class and tell me the name of the first method with a red squiggly under it.
Was This Post Helpful? 1
  • +
  • -

#42 bhsanchez72  Icon User is offline

  • D.I.C Head

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

Re: ACSL Golf Code errors

Posted 01 October 2011 - 03:13 PM

View PostGregBrannon, on 01 October 2011 - 03:11 PM, said:

Okay. I had that. Now look at the other class and tell me the name of the first method with a red squiggly under it.

i know i need two methods name tallyBScores and tallyAScores these have red squigglys.
Was This Post Helpful? 0
  • +
  • -

#43 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: ACSL Golf Code errors

Posted 01 October 2011 - 03:14 PM

Let me get it all working and I'll be right back.
Was This Post Helpful? 0
  • +
  • -

#44 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: ACSL Golf Code errors

Posted 01 October 2011 - 03:34 PM

Ready to go. Getting it all to work I realized I had a typo in ACSLGolfClient. Change the second tallyAScores at line 35 to tallyBScores. Got that? tallyBScores is your method, but you get to see mine first.

My method is tallyAScores.

In addition to the code below, a new type int class field needs to be added called aScore. So at line 12 of GolfScore, add:
    private int aScore = 0;

We'll end up deleting or writing over the existing method tallyScores(), so you can do that with my new method or with the one you'll be writing. When you're done adding my new method and writing yours, post the updated version of GolfScore.

My tallyAScores() method is below:

    // method tallyAScores() accepts an int value, s, and increments
    // the value aScore by the int value s
    public void tallyAScores(int s)
    {
        aScore += s;
    }


Your turn. Past my code into GolfScore, you write the method tallyBScores(), and then post the updated version of GolfScore. Don't forget to fix my typo in ACSLGolfClient.
Was This Post Helpful? 1
  • +
  • -

#45 bhsanchez72  Icon User is offline

  • D.I.C Head

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

Re: ACSL Golf Code errors

Posted 01 October 2011 - 03:49 PM

View PostGregBrannon, on 01 October 2011 - 03:34 PM, said:

Ready to go. Getting it all to work I realized I had a typo in ACSLGolfClient. Change the second tallyAScores at line 35 to tallyBScores. Got that? tallyBScores is your method, but you get to see mine first.

My method is tallyAScores.

In addition to the code below, a new type int class field needs to be added called aScore. So at line 12 of GolfScore, add:
    private int aScore = 0;

We'll end up deleting or writing over the existing method tallyScores(), so you can do that with my new method or with the one you'll be writing. When you're done adding my new method and writing yours, post the updated version of GolfScore.

My tallyAScores() method is below:

    // method tallyAScores() accepts an int value, s, and increments
    // the value aScore by the int value s
    public void tallyAScores(int s)
    {
        aScore += s;
    }


Your turn. Past my code into GolfScore, you write the method tallyBScores(), and then post the updated version of GolfScore. Don't forget to fix my typo in ACSLGolfClient.

Okay i was doing what you said but then it told me to get getters and setters for the tally scores a and b:
/*
 * Bradley Sanchez
 * This class maintains par, score, and total
 * 9/26/11
 * PD:4B CS2
 */

public class GolfScore 
{
	//private data
	private int par, aScore, bScore;
	
	//default constructor
	public GolfScore()
	{
		par = 0;
		setaScore(0);
		setbScore(0);
	}
	
	public void tallyPar(int p)
	{
		par += p;
	}
	
	public void tallyAScores(int a)
	{
	    setaScore(getaScore() + a);
	}
	
	public void tallybScores(int B)/>
	{
	    setaScore(getaScore() + B)/>;
	}
	
	public int getpar()
	{
		return par;
	}
	
	public int getScore()
	{
		return aScore;
	}
	
	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";
				
	}

	public int getaScore() {
		return aScore;
	}

	public void setaScore(int aScore) {
		this.aScore = aScore;
	}

	public int getbScore() {
		return bScore;
	}

	public void setbScore(int bScore) {
		this.bScore = bScore;
	}

}


Whats next!
Was This Post Helpful? 0
  • +
  • -

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »