import java.util.*; public class Card { /* Data members ********************************************************/ public enum Rank { ACE, DEUCE, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING } public enum Suit { HEART, SPADE, DIAMOND, CLUB } public enum Face { UP, DOWN } /* the final makes rank and suit immutable which a card should be like */ private final Rank rank; private final Suit suit; /* careful to allow face to be changeable so that we can flip cards */ private Face face; /* the linked list that the constructor should return containing a whole deck of cards */ private static final List CardDeck = new ArrayList(); /* Methods *************************************************************/ /* Card( ... ) purpose: The constructor is private to prevent it being called from outside of the class. It assigns the instance variables rank and suit values. */ private Card( Rank rank, Suit suit ) { /* assigns the rank and suit of the class some values */ this.rank = rank; this.suit = suit; this.face = Face.DOWN; } /* Basic information methods */ public Rank getRank() { return this.rank; } public Suit getSuit() { return this.suit; } public Face getFace() { return this.face; } public String toString() { return rank + " of " + suit + " face: " + face; } /* flip a card so that it faces up instead of down */ public void flip() { if( face == Face.DOWN ) face = Face.UP; else face = Face.DOWN; } static { /* go through each Suit and Rank value so as to create every combination of the two enumerations and add it to the CardDeck */ for( Suit suit : Suit.values() ) for( Rank rank : Rank.values() ) CardDeck.add(new Card( rank, suit ) ); } /* getDeck() purpose: Creates a copy of CardDeck which it returns returns: A CardDeck linked list with 52 Card objects in it.*/ public static final ArrayList getDeck() { /* Return a copy of CardDeck */ return new ArrayList( CardDeck ); } }