Hw#7
Hw#7
Modify the
compareTo method to implement this ordering.
Instead of modifying the compareTo method, you can also change the RANKS array so Aces
are ranked higher than Kings. Show me how you would do that.
if (rankIndex == otherRankIndex) {
return this.suit.compareTo(other.suit);
} else if (rankIndex == 1 && otherRankIndex != 1) {
return 1;
} else if (rankIndex != 1 && otherRankIndex == 1) {
return -1;
} else {
return Integer.compare(rankIndex, otherRankIndex);
}
}
}
2.A flush is a hand of 5 cards when the suit is the same. Write a method hasFlush that takes in
an array of 5 cards and return 1 when the hand is a flush.
If any card has a different suit, the method returns 0 (false). If all cards have the same suit, the
method returns 1 (true).
3. A “royal flush” includes the Ace, King, Queen, Jack, and 10 (all in the same suit). Write a
method called hasRoyal that determines whether an array of cards contains a royal flush.