I am unsure how to go about setting up a method in a golf Player class. This class calls on other methods of another class called ScoreCard so I will include that class here as well. Player class:
public class Player
{
private String name;
private ScoreCard card;
private int longestDrive;
private int fullDriveYards;
private int fullDrives;
private int drivesOnTarget;
public Player(String PlayerName)
{
if (PlayerName == null)
{
this.name = "Unknown";
}
else
{
this.name = PlayerName;
}
}
this.card = new ScoreCard;
this.longestDrive = 0;
this.fullDriveYards = 0;
this.fullDrives = 0;
this.drivesOnTarget = 0;
}
// This is the method I need help on
public void recordPlayer(int hole, int strokes, int driveYds, String location)
{
// make sure the hole number is valid
this.card = new ScoreCard();
card.getHolesPlayed();
if (true)
{
// replace condition below with a test for valid hole
// I will list the conditions in a second after I am done showing the classes
// record player's score on this hole
card.getTotalStrokes();
// use this.card and call on a ScoreCard method
this.card.recordScore(0, 0);
// define the conditions under which values of each of the int-type
// variables are adjusted and the new values they will have
}
public String getName()
{
return this.name;
}
public int getLongestDrive()
{
return this.longestDrive;
}
public int getFullDrives()
{
return this.fullDrives;
}
public int fullDriveYds()
{
return this.fullDriveYards;
}
public double computeFullAvg()
{
return 0.0;
}
public int getDrivesOnTarget()
{
return this.drivesOnTarget;
}
public double computeAccuracy()
{
return 0.0;
}
public String toString()
{
String playerReport = this.card.toString();
// add their driving statitics
playerReport = playerReport + "\nLongest Full Drive: " +
this.getLongestDrive();
playerReport = playerReport + "\nAverage Full Drive: " +
this.computeFullAvg();
playerReport = playerReport + "\nDriving Accuracy: " +
this.computeAccuracy();
}
}
Here is the ScoreCard Class:
public class ScoreCard
{
private int totalStrokes;
private int versusPar;
private LinkedList<Integer> playerScoreCard;
public ScoreCard()
{
// initialise instance variables
totalStrokes = 0;
versusPar = 0;
playerScoreCard = new LinkedList<Integer>();
}
public void recordScore(int inHole, int inStrokes)
{
// put your code here
if ((inHole >= 1) && (inHole <= playerScoreCard.size() + 1)) {
playerScoreCard.add(inHole - 1, inStrokes);
}
totalStrokes += inStrokes;
versusPar += (inStrokes - Course.getHole(inHole).getPar());
}
public int getHolesPlayed()
{
return playerScoreCard.size();
}
public int getTotalStrokes()
{
return totalStrokes;
}
public int getVersusPar()
{
return versusPar;
}
public String toString()
{
return "Holes Played: " + getHolesPlayed() + "\n" +
"Total Strokes: " + getTotalStrokes() + "\n" +
"Versus Par: " + getVersusPar();
}
}
Now here are the conditions for the Player class recordPlay method: The recordPlay method calls on a method of the related ScoreCard instance to record the player's score on the hole. IT also adjusts the values of other instance variables using the following rules:
- A drive is considered on target only if the recorded location is "Fairway" or "Green."
- A drive counts as full drive if: a) it is recorded on a hole of sufficient length (any length that is 400 yards and greater and use the isFullDriveHole ) b) The drive location is on target.
- Only full drives are considered for being the longest drive
I am done with mostly everything except the recordPlay method it's really giving me some trouble