我正在玩哎呀 pig 游戏。其中我遇到错误:“找不到符号类名称”
。你能帮我找到它吗?
public class Player
{
protected String name;
Scorekeeper sk;
// sk = new ScoreKeeper();
public Player(String name)
{
this.name = name;
//Scorekeeper sk = new ScoreKeeper();
sk = new ScoreKeeper();
}
public Player(){ }
public int getScore()
{
return sk.getGameTotal;
}
public String getName()
{
return name;
}
public int incScore(int rollValue)
{
sk.addToRoundTotal(rollValue);
return sk.getRoundTotal;
}
public int setScore()
{
return sk.resetRoundTable();
}
}
这是我为 ScoreKeeper
类创建对象的类,另一个类是
public class ScoreKeeper {
int gametotal = 0;
int roundtotal = 0;
public ScoreKeeper()
{
//gametotal = 0;
//roundtotal = 0;
}
public void addToGameTotal() {
gametotal += roundtotal;
resetRoundTotal();
}
public void addToRoundTotal(int value) {
roundtotal += value;
}
public void resetRoundTotal() {
roundtotal = 0;
}
public int getRoundTotal() {
return roundtotal;
}
public int getGameTotal() {
return gametotal;
}
}
当我尝试编译类时
Player.java:5: cannot find symbol
symbol : class Scorekeeper
location: class Player
Scorekeeper sk;
^
1 error
最佳答案
在你的 Player 类中你写道:
Scorekeeper sk;
“k”需要大写,如下所示:
ScoreKeeper sk;
Java 是区分大小写的语言
关于java - "cannot find symbol "oop pig 游戏错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16075278/