我正在做oop猪游戏.我遇到了一个错误:" cannot find symbol class name".你能帮我找到它吗?
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();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我为类创建对象的类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;
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译课程时
Player.java:5: cannot find symbol
symbol : class Scorekeeper
location: class Player
Scorekeeper sk;
^
1 error
Run Code Online (Sandbox Code Playgroud)
在您的Player类中,您写道:
Scorekeeper sk;
Run Code Online (Sandbox Code Playgroud)
"k"需要像这样大写:
ScoreKeeper sk;
Run Code Online (Sandbox Code Playgroud)
Java是一种区分大小写的语言