import java.util.Collections; import java.util.List; import java.util.LinkedList; import java.util.Queue; public class Deck { private Queue cards; public Deck() { List cards = new LinkedList(); int[] suits = {Card.CLUBS, Card.DIAMONDS, Card.HEARTS, Card.SPADES}; int[] specialRanks = {Card.JACK, Card.QUEEN, Card.KING, Card.ACE}; /* Add all the cards to the deck */ for (int i = 0; i < suits.length; i++) { /* Add standard ranks to deck */ for (int j = 2; j <= 10; j++) { cards.add(new Card(suits[i], j)); } /* Add special ranks to deck */ for (int j = 0; j < specialRanks.length; j++) { cards.add(new Card(suits[i], specialRanks[j])); } } /* Randomize the cards */ Collections.shuffle(cards); this.cards = (LinkedList)cards; } public boolean isEmpty() { return cards == null || cards.isEmpty(); } public Card dealCard() { if (cards == null || cards.isEmpty()) { throw new IllegalStateException(); } return cards.remove(); } public String toString() { return cards.toString(); } }