0

我在做oop pig游戏。我遇到一个错误:“ 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();
    }
  }    

这是我为该类创建对象的类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
4

1 回答 1

5

在您的 Player-class 中,您写道:

Scorekeeper sk;

“k”需要大写,如下所示:

ScoreKeeper sk;

Java 是区分大小写的语言

于 2013-04-18T05:42:19.793 回答