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
有任何想法,我应该如何设置numberOfPlayers分配值给playerId?以及如何执行calculateAverage和calculateBestScore方法?
我现在的代码是:
//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()
{
}
}
构造函数将增加静态变量numberOfPlayers,然后将numberOfPlayers的值分配给playerId
为变量提供static
标识符,并初始化它:
private static int numberOfPlayers = 0;
每次创建新的Player类时,将其递增1:
public Person() {
numberOfPlayers++;
}
public static int getNumPlayers() {
return numberOfPlayers;
}
Person a = new Person();
Person b = new Person();
Person c = new Person();
System.out.println(c.getNumPlayers()); //will be 3 based on the above
private ArrayList<Integer> scores = new ArrayList<Integer>();
public Person() {
}
public void setScore(int score) {
scores.add(score);
}
然后,这需要转到数据库,该数据库向工作人员发送返回消息,告诉他们该成员已被添加。 只有工作人员在和系统通话,没有人。
我目前正在做一个项目,我们必须从UML图制作代码。我了解UML类图的解剖结构,但我无法理解什么
第1034行:Char 9:运行时错误:引用绑定到'std::vector'类型的空指针
下面是我上传数据的Json格式,但它显示了错误,即在[source:(PushbackInputStream);line:1,column:2]]2021-05-04 12:57:07.799 WARN 876----[nio-9090-exec-4].W.S.M.S.DefaultHandlerExceptionResolver:Resolved[org.springframework.http
以 SaaS 产品形态为企业及个人提供地理信息服务,用最简单的方式制作最专业的地图,把地理智慧最大限度的延伸;从而辅助企业进行数据管理,业务决策,打造专属的地图应用服务。
图表秀,简单好用的在线图表制作网站,图表秀是东软数据可视化团队潜心开发的一款用于在线图表制作的产品,操作简单易懂, 而且网站内包含多种图表,涉及各行各业的报表数据都可以用图表秀实现。