【发布时间】:2017-03-19 02:29:23
【问题描述】:
/* 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;
}
正如它在 cmets 中所述,我试图在获胜者方法中返回winningScore() 结果,以便返回获胜者/获胜者的姓名。
我设法只返回了所有的获胜者,但我有点困惑是否应该从 winsScore() 方法调用它?
我知道我当前的代码对于获胜者来说是不正确的
任何正确方向的推动/提示将不胜感激!谢谢!
【问题讨论】:
-
看来您应该从
winners()方法调用winningScore()以...例如int scoreToMatch = winningScore();。然后遍历所有玩家并查看哪些玩家拥有该分数。 -
@Jon Skeet 谢谢!
标签: java string arraylist return