/* 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