solved Task 2
This commit is contained in:
parent
5e94dc5f40
commit
472af19faf
|
@ -77,7 +77,7 @@ class AlphaComparatorCompetitor implements Comparator<Competitor> {
|
|||
@Override
|
||||
public int compare(Competitor o1, Competitor o2) {
|
||||
// TODO Implement
|
||||
int c = 0;
|
||||
int c = o1.compareTo(o2);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,34 @@
|
|||
package ch.zhaw.ads;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class RankingListServer implements CommandExecutor {
|
||||
|
||||
public List<Competitor> createList(String rankingText) {
|
||||
// TODO Implement
|
||||
return null;
|
||||
List<Competitor> competitorList = new LinkedList<>();
|
||||
for(String listEntry : rankingText.split("\\n")){
|
||||
String[] entry = listEntry.split(";");
|
||||
competitorList.add(new Competitor(0, entry[0], entry[1]));
|
||||
}
|
||||
competitorList.sort(new AlphaComparatorCompetitor());
|
||||
int rank = 1;
|
||||
for(Competitor competitor : competitorList){
|
||||
competitor.setRank(rank);
|
||||
rank++;
|
||||
}
|
||||
return competitorList;
|
||||
}
|
||||
|
||||
public String createSortedText(List<Competitor> competitorList) {
|
||||
// TODO Implement
|
||||
return "";
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int rank = 1;
|
||||
for (Competitor competitor : competitorList) {
|
||||
stringBuilder.append(rank).append(" ").append(competitor.getName()).append(" ").append(competitor.getTime()).append("\n");
|
||||
rank++;
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public String createNameList(List<Competitor> competitorList) {
|
||||
|
|
Loading…
Reference in New Issue