From 15e14023db09c32cb383c06d185971251fa15624 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Tue, 15 Nov 2022 13:27:25 +0100 Subject: [PATCH] solved Task 2 --- src/ch/zhaw/ads/MyCompetitor.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ch/zhaw/ads/MyCompetitor.java b/src/ch/zhaw/ads/MyCompetitor.java index 0e14684..36170c9 100644 --- a/src/ch/zhaw/ads/MyCompetitor.java +++ b/src/ch/zhaw/ads/MyCompetitor.java @@ -48,18 +48,23 @@ public class MyCompetitor implements Comparable { @Override public int compareTo(MyCompetitor o) { // to be done - return -1; + int rankDiff = rank - o.rank; + int nameDiff = name.compareTo(o.name); + return 10000 * rankDiff + nameDiff; } @Override public int hashCode() { // to be done - return -1; + return rank % 3500 + name.hashCode() ; } @Override public boolean equals (Object o) { // to be done - return false; + if(! (o instanceof MyCompetitor)){ + return false; + } + return compareTo((MyCompetitor) o) == 0; } }