solved Task 4
This commit is contained in:
parent
77042b8d85
commit
4d62d5b7d8
|
@ -77,7 +77,7 @@ class AlphaComparatorCompetitor implements Comparator<Competitor> {
|
|||
@Override
|
||||
public int compare(Competitor o1, Competitor o2) {
|
||||
// TODO Implement
|
||||
int c = o1.compareTo(o2);
|
||||
int c = o1.getName().compareTo(o2.getName());
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ch.zhaw.ads;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,12 +18,18 @@ public class RankingListServer implements CommandExecutor {
|
|||
|
||||
public String createSortedText(List<Competitor> competitorList) {
|
||||
// TODO Implement
|
||||
competitorList.sort(new AlphaComparatorCompetitor());
|
||||
competitorList.sort(new Comparator<Competitor>() {
|
||||
@Override
|
||||
public int compare(Competitor o1, Competitor o2) {
|
||||
int c = o1.compareTo(o2);
|
||||
return c;
|
||||
}
|
||||
});
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int rank = 1;
|
||||
for (Competitor competitor : competitorList) {
|
||||
competitor.setRank(rank);
|
||||
stringBuilder.append(rank).append(" ").append(competitor.getName()).append(" ").append(competitor.getTime()).append("\n");
|
||||
stringBuilder.append(competitor.toString()).append("\n");
|
||||
rank++;
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
|
@ -29,9 +37,11 @@ public class RankingListServer implements CommandExecutor {
|
|||
|
||||
public String createNameList(List<Competitor> competitorList) {
|
||||
// TODO Implement
|
||||
competitorList.sort(new AlphaComparatorCompetitor());
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int rank = 0;
|
||||
for (Competitor competitor : competitorList) {
|
||||
stringBuilder.append(competitor.getName()).append(" ").append(competitor.getTime()).append("\n");
|
||||
stringBuilder.append(competitor.toString()).append("\n");
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue