From 4b03f5d629378f78da69e8d4c3f65038f7f76d91 Mon Sep 17 00:00:00 2001 From: peet Date: Sun, 12 May 2024 15:05:39 +0200 Subject: [PATCH] implemented compareTo method --- bin/cards/Card.class | Bin 2064 -> 2216 bytes src/cards/Card.java | 12 ++++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/cards/Card.class b/bin/cards/Card.class index 41dcbd5226796d77c67b411f3b43de4619aba86e..97f026e02cedb6e06af446bf6ff6a542114cd3ba 100644 GIT binary patch delta 524 zcmXX?J5y6p5dQYQPP`M4BxuA$U>F!M0fJ9ZL_tK121NtDUnh}447vACNE|zUg3cTp z8*2+1M~5PXjh&r^Kg7b$ar}G~XLrBH?wQ?JUGEb9mtXBq0OnAA?;o@(J`Q0ljvU4X zsgcq%{ahC|b+BGo2wL^&!$ltx7*jYR@TL#v~lZ4C1^*7y5_?u%Ar-zbQ!L z01@ZmC@Y~aiDNjCxQ1I? eLvR~+aS!*Y_(Tuz2pT=85O>n45M#B68h!&323TSM delta 376 zcmXYrJ5K^p5QWd(y}NhWpn(KI#cU-Zg0ct-z7X(@f^YHBo7kBcWBdh1JCkYr2^Jc) zv7jIrJ1c*Nm5H%8&Z4==oH=v8$=uuEb-;f6X*2*z%hdzw&LJqvlKhpF&ucC{q$ul5|FxT*3iU_*d zdBh-hf}g?=)m28M=t`v{F48>fU?R?px33Zn4AZ-E^ejf`ONGQJyQmW=BZ0Ahcz|K= zyf2Y#K|EueidJ83vVCX@g|<$k$Qoj9p0^gT3dy>L4QyhI6Pw*O>exdM_SttbsbF#E G;|#xNcsacQ diff --git a/src/cards/Card.java b/src/cards/Card.java index 561feb4..3600c77 100644 --- a/src/cards/Card.java +++ b/src/cards/Card.java @@ -23,7 +23,15 @@ public record Card(Rank rank, Suit suit) implements Comparable { */ @Override public int compareTo(Card other) { - //TODO implement - return 0; + // First, compare ranks + int rankComparison = this.rank.compareTo(other.rank); + + if (rankComparison != 0) { + // If ranks are different, return the comparison result + return rankComparison; + } else { + // If ranks are equal, compare suits + return this.suit.compareTo(other.suit); + } } }