UML:
-name: String
-playerId: int
-scores: int[]
-bestScore: int
-numberOfPlayers: int
<< constructors>>
+Player()
+Player(name: String)
<< set methods>>
+setName(name: String):void
+setScores(score: int[]):void
<< get methods >>
+getPlayerId():int
+getName():String
+getScores():int[]
+getBestScore(): int
+calculateAverage(): double
<< helper methods >>
-calculateBestScore(): void
- The constructors will increment the static variable numberOfPlayers and then assign the value of numberOfPlayers to the playerId.
- The calculateAverage() public method determines the average score for a player from the data stored in the scores array.
- The getBestScore() method calls the calculateBestScore() private helper method to determines the highest score achieved so far by a player.
Any ideas how should i set the numberOfPlayers assign value to playerId ? And how to I do the calculateAverage and calculateBestScore methods ?
My code at the moment is:
//Class declaration of Player class
public class Player
{
/*--------------- Data Fields --------------------------------------
Attributes of the class
*/
private String name;
private int playerId;
private int bestScore;
private int numberOfPlayers;
private int scores;
/* -------------- CONSTRUCTOR --------------------------------------
*/
public Player(String name)
{
this.name = name;
this.numberOfPlayers = numberOfPlayers + 1;
this.playerId = this.numberOfPlayers;
}
//Create set method for setName
public void setName(String name)
{
this.name = name;
}
//Create set method for setScores
public void setScore(int score)
{
scores = score;
}
//Create get method for getPlayerId
public int getPlayerId()
{
return playerId;
}
//Create get method for getName
public String getName()
{
return name;
}
//Create get method for getScores
public int getScores()
{
return scores;
}
//Create get method for getBestScore
public int getBestScore()
{
return bestScore;
}
//Create get method for calcualteAverage
public double calculateAverage()
{
}
}