ACSL Golf Code errors

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

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

#1 bhsanchez72  Icon User is offline

  • D.I.C Head

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

ACSL Golf Code errors

Posted 01 October 2011 - 07:23 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 that i have right now but i really need some help with these errors and i am not even sure if I am doing it right.

Client
/*
 * Bradley Sanchez
 * This class will show the golf scores
 * 9/30/11
 * PD:4B 
 * CS2
 */
import java.io.File;
import java.io.IOException;
import java.util.Scanner;


public class GolfingClient 
{
	public static void main(String[] args)  throws IOException
	{
		int parValue, parTotal = 0, playerA, playerB, totalA = 0, totalB = 0, counter = 0, highScoreA, highScoreB, highScore, aHolesWon = 0, bHolesWon = 0;
		
		for (int line = 1; line <= 9; line++)
		{
			parValue = dataIn.nextInt();
			playerA = dataIn.nextInt();
			playerB = dataIn.nextInt();
			
			counter++;
			parTotal += parValue;
			totalA += playerA;
			totalB += playerB;
			
			//access the class with the data
			myGolfScore.tallyPar(par);
			myGolfScore.tallyScores(score);
			
			//output results
			System.out.println(myGolfScore.outcome(par, score));
			System.out.println(totalScore);
			
			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
/*
 * 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";
				
	}

}


There that is what i have right now and if i try to run it, it will say Error: Could not find or load main class ACSLGolfClient. So if you could help me for what i need to change so i can get all of those outputs, That would be GREAT.

This post has been edited by macosxnerd101: 01 October 2011 - 09:12 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: ACSL Golf Code errors

#2 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 - 07:27 AM

First things first: Please post your code in code tags. Instructions how are everywhere.

Then your error message: The name of your source file, the part before .java, has to be the same as your top-level public class. Your filename is ACSLGolfClient.java, and your top-level class is called, GolfingClient. Change one to the other, rerun, and come back with an update on your problems.

Don't forget to post code in code tags.
Was This Post Helpful? 0
  • +
  • -

#3 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • Posts: 3,002
  • Joined: 30-January 11

Re: ACSL Golf Code errors

Posted 01 October 2011 - 07:27 AM

AAAH, the lack of code tags hurts my eyes!

What is ACSLGolfClient? Is it the name of a Java source file? If it is, you need to change it to the actual name of the class that resides within it.

Also please use [code] tags in future post :)

Edit: Ninja'd

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

Was This Post Helpful? 0
  • +
  • -

#4 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 - 07:44 AM


[quote name='Ryano121' date='01 October 2011 - 07:27 AM' timestamp='1317479227' post='1449056']
AAAH, the lack of code tags hurts my eyes!

What is ACSLGolfClient? Is it the name of a Java source file? If it is, you need to change it to the actual name of the class that resides within it.

Also please use
 tags in future post :)/>

Edit: Ninja'd
[/quote]
[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);
//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();
System.out.println("Please enter your score for playerA --> ");
playerA = kbd.nextInt();
System.out.println("Please enter your score for playerB --> ");
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 what i have now and i need to figure out how to get the right outputs. Thanks!
Was This Post Helpful? 0
  • +
  • -

#5 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • Posts: 3,002
  • Joined: 30-January 11

Re: ACSL Golf Code errors

Posted 01 October 2011 - 07:46 AM

Well what errors are you getting? What output are you getting that is unexpected?
Was This Post Helpful? 0
  • +
  • -

#6 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 - 07:49 AM

View PostRyano121, on 01 October 2011 - 07:46 AM, said:

Well what errors are you getting? What output are you getting that is unexpected?


This is the output i am getting:
Please enter par for the hole -->
3
Please enter your score for playerA -->
2
Please enter your score for playerB -->
3
a score equal to par
0
Please enter par for the hole -->
And if you look above in the problem that is not what i need so i need to change this class below but not sure what to do.

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

}

}
Thanks!
Was This Post Helpful? 0
  • +
  • -

#7 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 - 08:10 AM

Code tags! It's very hard to discuss your code without them. You can edit your last post:

1) select the code (highlight it),
2) press the [CODE] tool in the tool bar above the edit area.
Was This Post Helpful? 1
  • +
  • -

#8 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 - 08:18 AM

[quote name='GregBrannon' date='01 October 2011 - 08:10 AM' timestamp='1317481856' post='1449081']
Code tags! It's very hard to discuss your code without them. You can edit your last post:

1) select the code (highlight it),
2) press the
 tool in the tool bar above the edit area.
[/quote]
Here you go sorry about that now can you please help me in getting the correct outputs.
This is the output i am getting:
[code]Please enter par for the hole -->
3
Please enter your score for playerA -->
2
Please enter your score for playerB -->
3
a score equal to par
0
Please enter par for the hole -->

And if you look above in the problem that is not what i need so i need to change this class below but not sure what to do.

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

}

}

Thanks!
Was This Post Helpful? 0
  • +
  • -

#9 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 - 08:30 AM

Your first class, GolfingClient, is below. Notice how the code is formatted to improve readability.

Questions:

Assuming the data is to be read from the keyboard, what is dataIn? (Correct my assumption, if necessary).
Why does GolfScore.outcome() return "birdie," "eagle," etc? There's no mention of that in the problems statement.
Lines 26 - 33 (below): what if there's a tie?
Edit: I forgot: What are myGolfScore, par, score, totalScore?

public class GolfingClient
{
    public static void main(String[] args) throws IOException
    {
        int parValue, parTotal = 0, playerA, playerB, totalA = 0, totalB = 0, counter = 0, highScoreA, highScoreB, highScore, aHolesWon = 0, bHolesWon = 0;

        for (int line = 1; line <= 9; line++)
        {
            parValue = dataIn.nextInt();
            playerA = dataIn.nextInt();
            playerB = dataIn.nextInt();

            counter++;
            parTotal += parValue;
            totalA += playerA;
            totalB += playerB;

            //access the class with the data
            myGolfScore.tallyPar(par);
            myGolfScore.tallyScores(score);

            //output results
            System.out.println(myGolfScore.outcome(par, score));
            System.out.println(totalScore);

            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 post has been edited by GregBrannon: 01 October 2011 - 08:33 AM

Was This Post Helpful? 0
  • +
  • -

#10 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 - 08:44 AM

View PostGregBrannon, on 01 October 2011 - 08:30 AM, said:

Your first class, GolfingClient, is below. Notice how the code is formatted to improve readability.

Questions:

Assuming the data is to be read from the keyboard, what is dataIn? (Correct my assumption, if necessary).
Why does GolfScore.outcome() return "birdie," "eagle," etc? There's no mention of that in the problems statement.
Lines 26 - 33 (below): what if there's a tie?
Edit: I forgot: What are myGolfScore, par, score, totalScore?

public class GolfingClient
{
    public static void main(String[] args) throws IOException
    {
        int parValue, parTotal = 0, playerA, playerB, totalA = 0, totalB = 0, counter = 0, highScoreA, highScoreB, highScore, aHolesWon = 0, bHolesWon = 0;

        for (int line = 1; line <= 9; line++)
        {
            parValue = dataIn.nextInt();
            playerA = dataIn.nextInt();
            playerB = dataIn.nextInt();

            counter++;
            parTotal += parValue;
            totalA += playerA;
            totalB += playerB;

            //access the class with the data
            myGolfScore.tallyPar(par);
            myGolfScore.tallyScores(score);

            //output results
            System.out.println(myGolfScore.outcome(par, score));
            System.out.println(totalScore);

            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);
        }
    }   
}

I got rid of the dataIns and it is showing eagle and birdie etc. because i used this class for a different problem and now i am changing it for this problem. The birdie stuff was for the other problem and i don't now how to change it so i get the right outputs for this problem. Thanks!
Below is my latest client and in my other post is the second class where i have to change the if and else statement to get the right outputs.

/*
 * 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);
		//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();
			System.out.println("Please enter your score for playerA --> ");
			playerA = kbd.nextInt();
			System.out.println("Please enter your score for playerB --> ");
			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);
		}
}
		
	}

Was This Post Helpful? 0
  • +
  • -

#11 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 - 08:57 AM

You wrote this code? If you had, I think you'd know how to change it to fit the new problem - if that were even a good idea.

The first thing that needs to be done to fit the new problem is to modify lines 28 - 45 to obtain the data in 9 lines of 3 numbers separated by commas. I'm still not sure how those 9 lines are provided. By keyboard? From a file? If you know, program accordingly. Otherwise, assume keyboard entry, and it can be modified later, if necessary.

So, give the user a prompt, something like, "Enter line 1 (par, scoreA, scoreB): ", and then accept the 3 numbers entered by the user. Start with getting one line to work, then do multiple lines.
Was This Post Helpful? 1
  • +
  • -

#12 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 - 09:10 AM

View PostGregBrannon, on 01 October 2011 - 08:57 AM, said:

You wrote this code? If you had, I think you'd know how to change it to fit the new problem - if that were even a good idea.

The first thing that needs to be done to fit the new problem is to modify lines 28 - 45 to obtain the data in 9 lines of 3 numbers separated by commas. I'm still not sure how those 9 lines are provided. By keyboard? From a file? If you know, program accordingly. Otherwise, assume keyboard entry, and it can be modified later, if necessary.

So, give the user a prompt, something like, "Enter line 1 (par, scoreA, scoreB): ", and then accept the 3 numbers entered by the user. Start with getting one line to work, then do multiple lines.

My teacher helped me with the first parts of the code and thus is really the first time i am doing it by myself and my teacher is terrible and dose not teach us well, so i changed the kbd lines. Did i do that right and whats next, see once i get this code done i will have learned how to do it and use it as a template for others. Thanks! so much

/*
 * 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);
		//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, scoreA, scoreB --> ");
			parValue = 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);
		}
}
		
	}

Was This Post Helpful? 0
  • +
  • -

#13 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 - 09:37 AM

That may get you one value from the user. What have you learned about that may help you get more than one? Have you heard of Regex or Scanner.useDelimiter()? Or are you just supposed to figure it out?
Was This Post Helpful? 1
  • +
  • -

#14 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 - 09:40 AM

View PostGregBrannon, on 01 October 2011 - 09:37 AM, said:

That may get you one value from the user. What have you learned about that may help you get more than one? Have you heard of Regex or Scanner.useDelimiter()? Or are you just supposed to figure it out?

No i have not learned that yet sorry. But i do now i should use kbd keyboard.
Was This Post Helpful? 0
  • +
  • -

#15 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 - 10:13 AM

Well, you're going to have to expand your knowledge to get 3 ints from the single line of input. There are many ways to do it, but I think the most direct, staying within what you've learned, is to use Scanner's useDelimiter() method.

If you change line 18 to:

Scanner kbd = new Scanner(System.in).useDelimiter( ",|\n" );

That means that you want the input kbd broken or split at the characters ',' or '\n' (new line). That way, the string that kbd gets, e.g. "x,y,z", will be interpreted as 3 items, x, y, and z.

Then change lines 29, 30, and 31 (30 and 31 are new) to:
parValue = kbd.nextInt();
playerA = kbd.nextInt();
playerB = kbd.nextInt();

Those 3 lines get the values x, y, and z entered by the user and stores them as parValue, playerA, and playerB, respectively. I guessed that those were the right variables to use, so change them if I got it wrong.

So now you should be able to get 4 lines of input based on your for loop at line 20. You need to get 9 lines of input. Fix that next.
Was This Post Helpful? 1
  • +
  • -

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