102 Replies - 1876 Views - Last Post: 02 October 2011 - 06:36 PM
#31
Re: ACSL Golf Code errors
Posted 01 October 2011 - 02:19 PM
#32
Re: ACSL Golf Code errors
Posted 01 October 2011 - 02:33 PM
#33
Re: ACSL Golf Code errors
Posted 01 October 2011 - 02:41 PM
#34
Re: ACSL Golf Code errors
Posted 01 October 2011 - 02:46 PM
GregBrannon, on 01 October 2011 - 02:41 PM, said:
Can you make the first method and explain it then i will do the second one please.
#35
Re: ACSL Golf Code errors
Posted 01 October 2011 - 02:48 PM
Show me your for loop when you have it ready.
#36
Re: ACSL Golf Code errors
Posted 01 October 2011 - 02:53 PM
GregBrannon, on 01 October 2011 - 02:48 PM, said:
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);
}
}
}
bhsanchez72, on 01 October 2011 - 02:51 PM, said:
GregBrannon, on 01 October 2011 - 02:48 PM, said:
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.
#37
Re: ACSL Golf Code errors
Posted 01 October 2011 - 03:01 PM
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();
}
}
#38
Re: ACSL Golf Code errors
Posted 01 October 2011 - 03:03 PM
GregBrannon, on 01 October 2011 - 03:01 PM, said:
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
#39
Re: ACSL Golf Code errors
Posted 01 October 2011 - 03:05 PM
#40
Re: ACSL Golf Code errors
Posted 01 October 2011 - 03:09 PM
GregBrannon, on 01 October 2011 - 03:05 PM, said:
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
#41
Re: ACSL Golf Code errors
Posted 01 October 2011 - 03:11 PM
#42
Re: ACSL Golf Code errors
Posted 01 October 2011 - 03:13 PM
#43
Re: ACSL Golf Code errors
Posted 01 October 2011 - 03:14 PM
#44
Re: ACSL Golf Code errors
Posted 01 October 2011 - 03:34 PM
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.
#45
Re: ACSL Golf Code errors
Posted 01 October 2011 - 03:49 PM
GregBrannon, on 01 October 2011 - 03:34 PM, said:
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!
|
|

New Topic/Question
Reply




MultiQuote


|