From 4d62d5b7d813912e9cf2afb73c0353f28309492f Mon Sep 17 00:00:00 2001 From: schrom01 Date: Tue, 4 Oct 2022 14:17:57 +0200 Subject: [PATCH] solved Task 4 --- src/ch/zhaw/ads/Competitor.java | 2 +- src/ch/zhaw/ads/RankingListServer.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) 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(); }