错误:不兼容的类型返回分数; required:int found:ArrayList <integer> </integer>

时间:2015-04-03 21:47:32

标签: java

//Class declaration of Player class
public class Player
{
/*--------------- Data Fields ---------------------------------------
Attributes of the class
*/
private String name;
private int playerId;
private int bestScore;
private static int numberOfPlayers = 0;
private ArrayList<Integer> scores = new ArrayList<Integer>();

//Create set method for setScores
public void setScore(int score)
{
    scores.add(score);
}

//Create get method for getScores
public int getScores()
{
    return scores;
}
}

我尝试寻找解决方案,但似乎无法找到解决方案。我被要求为一个玩家存储5个分数用于猜谜游戏。我只是想知道我应该在getScore方法中加入什么。

1 个答案:

答案 0 :(得分:1)

看这里,问题出在这里:

public int getScores()
{
    return scores;
}

您从一个声明返回int

的方法返回一个ArrayList