Here is an example of a map class. Since questions indicate that Kost will have a specific class, while the Rank will be an integer (in this example, I did not apply the rank check). Implementing the Comparable class allows the Card class to compare another card class. So the list / set of cards can be sorted.
public class Card implements Comparable<Card>{ private SUIT cardSuit; private int cardRank; public enum SUIT {SPADE, CLUB, HEART, DIAMOND}; public Card(int cardRank, SUIT cardSuit) { this.cardSuit = cardSuit; this.cardRank = cardRank; } public Card(){ this((int) (Math.random() * 9) , SUIT.values()[(int) (Math.random() * SUIT.values().length)]); } public String getSuit() { return cardSuit.toString(); } public int getRank() { return cardRank; } @Override public int compareTo(Card2 o) { if (this.cardRank == o.cardRank) { return this.cardSuit.compareTo(o.cardSuit); } else { return o.cardRank - this.cardRank; } } }
source share