I'm stuck on this question where I need to compare two card objects based upon what rank and suit they are. Heart being the lowest suit, Spades the highest. And for Rank, One the lowest and Ace the highest. And 5 Spades being > 2 Hearts. These values are stored in two enums of their respective type. With Heart being the first ordinal and Spades the last ordinal.
@Override
public int compareTo(Card o) {
if(this.rank.ordinal() > o.rank.ordinal()) {
return 1;
}
if (this.rank.ordinal() < o.rank.ordinal()) {
return -1;
}
else {
return 0;
}
In my comapreTo() I've implemented the comparing of the rank, but I'm stuck on THEN comparing the suit to find the greater card. This code fails once it goes past Ace of Hearts as it thinks 1 of clubs is higher. I've tried a bunch of different methods using if's but it just becomes convoluted and ugly and doesn't work anyways. Does anyone have any suggestions?