implemented compareTo method

This commit is contained in:
Johannes Schmelz 2024-05-12 15:05:39 +02:00
parent 196ed3ec0f
commit 4b03f5d629
2 changed files with 10 additions and 2 deletions

Binary file not shown.

View File

@ -23,7 +23,15 @@ public record Card(Rank rank, Suit suit) implements Comparable<Card> {
*/ */
@Override @Override
public int compareTo(Card other) { public int compareTo(Card other) {
//TODO implement // First, compare ranks
return 0; 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);
}
} }
} }