diff --git a/src/ch/zhaw/ads/Competitor.java b/src/ch/zhaw/ads/Competitor.java index 3536c6b..02033d5 100644 --- a/src/ch/zhaw/ads/Competitor.java +++ b/src/ch/zhaw/ads/Competitor.java @@ -77,7 +77,7 @@ class AlphaComparatorCompetitor implements Comparator { @Override public int compare(Competitor o1, Competitor o2) { // TODO Implement - int c = o1.compareTo(o2); + int c = o1.getName().compareTo(o2.getName()); return c; } } diff --git a/src/ch/zhaw/ads/RankingListServer.java b/src/ch/zhaw/ads/RankingListServer.java index b6f23cd..95e12e9 100644 --- a/src/ch/zhaw/ads/RankingListServer.java +++ b/src/ch/zhaw/ads/RankingListServer.java @@ -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 competitorList) { // TODO Implement - competitorList.sort(new AlphaComparatorCompetitor()); + competitorList.sort(new Comparator() { + @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 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(); }