/* 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()メソッドから呼び出す必要がある場合は少し混乱していますか?
私は私の現在のコードが正しい方向に任意のプッシュ/ヒントをいただければ幸い勝者
に対して不適切であることを理解!ありがとう!
:あなたは
i
変数インデックスを使用していないので、 'int scoreToMatch = winningScore();'その後、すべてのプレイヤーをループし、どれが*そのスコアを持っているかを確認します。 –@Jon Skeetありがとう! – copernicon1543