// Note: This file uses "Javadoc" commenting formatting. You do not need to know this. /** * This class represents a standard card with a suit and a value. * * The suit should be "S" for Spades, "D" for Diamonds, "H" for hearts, or "C" for clubs. * The value of a numeric card should just be the number of that card. * The value of an Ace is 1, Jack is 11, Queen is 12, and King is 13. * @author Hunter Schafer, CSE 143 */ public class Card { // Note: This isn't the best way of representing a card because we // aren't constraining our values to the ones desired. In real life, // you would probably want to use something known as an enum to do this since // the cards are limited to a small set of values; however, we don't teach // enums in this class so don't worry about it. private String suit; private int value; /** * Constructs a card with the given suit and given value * See class comment for what values suit and value should take. * * @param suit - Suit of card * @param value - Numeric value for card (see class comment) */ public Card(String suit, int value) { this.suit = suit; this.value = value; } /** * Returns the suit of this card * @return this card's suit */ public String getSuit() { return this.suit; } /** * Returns the value of this card. See class comment for description of values. * @return this card's value */ public int getValue() { return this.value; } /** * Returns a String representation of this card. * Example: The Jack of clubs would return "[C Jack"] * The two of spades would return "[S 2]" * @return a String representation of this card */ public String toString() { return "[" + this.suit + " " + this.getValueString() + "]"; } // Returns a String representation of the value. // 1 is "Ace", 2-10 is just the number, 11 is "Jack", // 12 is "Queen", 13 is "King" private String getValueString() { if (this.value == 1) { return "Ace"; } else if (this.value == 11) { return "Jack"; } else if (this.value == 12) { return "Queen"; } else if (this.value == 13) { return "King"; } else { return "" + this.value; } } }