/* Assume as precondition that the list of players is not empty.
* Returns the winning score, that is, the lowest total score.
* @return winning score
*/
public int winningScore() {
Player thePlayer = players.get(0);
int result = thePlayer.totalScore();
for (int i = 0; i < players.size(); i++){
int p = players.get(i).totalScore();
if (p < result) {
result = players.get(i).totalScore();
}
}
return result;
}
/* Returns the list of winners, that is, the names of those players
* with the lowest total score.
* The winners' names should be stored in the same order as they occur
* in the tournament list.
* If there are no players, return empty list.
* @return list of winners' names
*/
public ArrayList<String> winners() {
ArrayList<String> result = new ArrayList<String>();
for (int i = 0; i < players.size(); i++)
if (!players.isEmpty())
return result;
}
因为它在注释中声明,所以我试图在winners方法中返回winningScore()结果,以便返回赢家/赢家名称。将数值从一种方法返回到另一种方法
我设法只返回所有的获奖者,但是如果它应该从winningScore()方法调用或者不是有点困惑?
我明白我当前的代码是不正确的赢家
在正确的方向推任何/提示,将不胜感激!谢谢!
那么它看起来像你应该调用'winningScore()'从'赢家()'方法入手...如'int scoreToMatch = winningScore();'。然后循环所有球员,看看哪些球员*得分*。 –
@Jon Skeet谢谢! – copernicon1543