001package hw0.optional;
002
003
004/**
005 * Represents one of 13 values (2-10, Jack, Queen, King, Ace) that appear
006 * on a playing card. This class is immutable.
007 */
008public enum CardValue  {
009
010    //
011    // CONSTANTS
012    //
013
014    // The 13 acceptable card values.
015
016    /**
017     * The card value representing 2.
018     */
019    TWO("two", "2"),
020
021    /**
022     * The card value representing 3.
023     */
024    THREE("three", "3"),
025
026    /**
027     * The card value representing 4.
028     */
029    FOUR("four", "4"),
030
031    /**
032     * The card value representing 5.
033     */
034    FIVE ("five", "5"),
035
036    /**
037     * The card value representing 6.
038     */
039    SIX ("six", "6"),
040
041    /**
042     * The card value representing 7.
043     */
044    SEVEN ("seven", "7"),
045
046    /**
047     * The card value representing 8.
048     */
049    EIGHT ("eight", "8"),
050
051    /**
052     * The card value representing 9.
053     */
054    NINE("nine", "9"),
055
056    /**
057     * The card value representing 10.
058     */
059    TEN ("ten", "10"),
060
061    /**
062     * The card value representing a Jack.
063     */
064    JACK ("Jack", "J"),
065
066    /**
067     * The card value representing a Queen.
068     */
069    QUEEN("Queen", "Q"),
070
071    /**
072     * The card value representing a King.
073     */
074    KING ("King", "K"),
075
076    /**
077     * The card value representing an Ace.
078     */
079    ACE ("Ace", "A");
080
081    //
082    // MEMBER VARIABLES
083    //
084
085    /**
086     * The name of this card value.
087     */
088    private String name;
089
090    /**
091     * The symbol representing this card value that appears on a playing card.  For
092     * the values 2-10, this symbol is simply the digits themselves; for JACK, QUEEN,
093     * KING, and ACE values, the symbols are "J", "Q", "K", and "A" respectively.
094     */
095    private String letterOnCard;
096
097    //
098    // METHODS
099    //
100
101    //-------------------------------------------
102    /**
103     * Creates a new card value.
104     *
105     * @param valueName  the name of this value
106     * @param letter     the symbol representing this card value that appears
107     *                   on a playing card
108     *
109     *
110     *
111     * @modifies this
112     * @effects  creates a new <code>CardValue</code> object
113     */
114    CardValue(String valueName, String letter) {
115        name = valueName;
116        letterOnCard = letter;
117    }
118
119    //-------------------------------------------
120    /**
121     * Returns the name of this value.
122     * <p>
123     * The value names can be either "2", "3", ..., "10", "Jack", "Queen", "King", or "Ace".
124     *
125     *
126     * @effects  returns the name of this value
127     */
128    public String getName() {
129        return name;
130    }
131
132    //-------------------------------------------
133    /**
134     * Returns the symbol representing this card value.
135     * <p>
136     * For the values 2-10, this symbol is simply the digits themselves; for JACK, QUEEN,
137     * KING, and ACE values, the symbols are "J", "Q", "K", and "A" respectively.
138     *
139     *
140     * @effects  returns the symbol representing this card value
141     */
142    public String getLetterOnCard() {
143        return letterOnCard;
144    }
145
146
147    //-------------------------------------------
148    /**
149     * Returns a description of this value.
150     *
151     *
152     * @effects  returns a description of this value
153     */
154    public String toString() {
155        return getName();
156    }
157
158}