0
나는 가장 낮은 점수를 얻고 arraylist를 만들어 승자를 얻으려고하는 토너먼트 강습을하고 있습니다. 내 winnersScore 메서드를 승자 메서드에 사용할 수있을 것 같습니까? 가장 낮은 점수를 가진 이름의 arraylist 만들기
이
내 시도 : (하지만 그들은 동일한 유형하지 않기 때문에 나는 오류와 끝까지)/**
* 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 몇 가지 방법이 승자 방법으로?
@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"));
}
어떤 도움이 크게 감사합니다 감사 :
/*
* 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 테스트입니다.
이 빈 목록이 비어있는 경우, 당신은 테스트 및 O 경우는 null를 돌려줍니다. 따라서 항상 null을 반환합니다. 그리고 절대로해서는 안됩니다. 메소드의 javadoc를 돌려주세요. –
당신 winnng 점수는 당신이 생각하는 바를 확신합니까? –