0
私はトーナメントのクラスを持っています。私は、最も低い得点を得て、それから作曲家を作って勝者を得ようとします。 winnerScoreメソッドを私の勝者メソッドに使うことができると思ったのですか? スコアの最も低い名前の作曲家を作成する
この
は私の試みです: (しかし、彼らは同じタイプではありませんので、私はエラーで終わる)/**
* 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>();
if (result.isEmpty()) {
return null;
}
result.add(players);
// Supply this code!
return result;
}
私は私が作ったこの方法を持って、それをincoperateするためにいくつかの方法があります勝者の方法に?
/*
* 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();
// Supply this code!
for(int i=0; i <par.length; i++)
if(par[i] > result)
result = par[i];
return result;
}
これは勝者方法のJUnitテストです:
@Test(timeout=3000)
public void testWinners() {
int [] par = {3,4,5,4,5,3,4,3,5,3,4,5,4,3,4,5,4,3};
int [] scores1 = {3,4,3,5,3,4,4,3,5,3,3,4,3,4,3,4,3,4};
int [] scores2 = {4,4,3,5,3,4,4,3,5,3,3,4,3,4,3,4,3,4};
int [] scores3 = {3,4,3,5,3,4,4,3,5,3,3,4,3,4,3,4,3,5};
Tournament T = new Tournament(par);
T.enter("Norman", 2, scores1);
T.enter("Palmer", 4, scores2);
T.enter("Scott", 1, scores3);
ArrayList<String> winners = T.winners();
assertTrue(winners.get(0).equals("Norman"));
}
すべてのヘルプは非常に感謝を理解されるであろう。
あなたはこの空のリストが空であるならば、あなたがテストし、空のリストを作成することによって開始し、O場合、nullを返します。だからあなたは常にnullを返します。そして、あなたは今までではいけません。メソッドのjavadocを返します。 –
あなたのwinnngスコアは、あなたが思っていることを確信していますか? –