java - "cannot find symbol "oop pig 游戏错误

标签 java oop class symbols

我正在玩哎呀 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/

相关文章:

java - 在 java 存储过程中创建 java.sql.blob 实例

oop - 如何在 MATLAB 中获取对象(类 inst)中的方法句柄

c++ - 如果您不知道传递的方法的确切类,如何将方法传递给类

c# - 从列表的自定义列中选择一个元素

javascript - 如何使用 javascript 或 java 获取当前 url 用户位于 .jsp 文件中

java - ZeroMQ 重新排序

java - 对现有 Web 应用程序使用 OAuth 2.0

objective-c - 我可以检测到: "Does class overload method of base class"?吗

php - OOP如何管理存储在不同文件中的 'include'类

c++ - 使用类模板 :error LNK2019 的 C++ 程序