I have got a class Card from which other cards(Card Game) inherit from. The Cards suits and number are stored in enums like this
public static enum Suit {
CLUBS, DIAMONDS, HEARTS, SPADES
};
public static enum Rank {
DEUCE, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE
};
My first problem is how to change the order of the cards ranks. In each separate class(Card Game) that inherits from class Card as different card games place different levels of importance on different cards.
My second problem is using the Comparable Interface.
So I have a class card like this:
public class Card implements Comparable<Card> {
public Suit suit;
public Rank rank;
public Card(Rank ranker, Suit suiter) {
rank = ranker;
suit = suiter;
}
//Other Methods for rank and suit here.
@Override
public int compareTo(Card o) {
int rankCom = rank.compareTo(o.rank);
return rankCom != 0 ? rankCom : suit.compareTo(o.suit);
}
}
I have just been recently introduced to the comparable interface and I am not entirely sure my implementation is right. The problem arises when I want to sort out my cards using collections.sort(cards_saver). cards_saver is where I store my cards. All of that works fine. collections.shuffle(cards_saver) also works fine. The problem I get when I do collections.sort is this:
Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments (List<Card>). The inferred type Card is not a valid substitute for the bounded parameter <T extends Comparable<? super T>>
I would have put up all the extra code I have...Only this is getting way too long. If I didn't explain the problems well enough, please comment-I will try to explain.
Thanks in Advance