// Hunter Schafer, CSE 143 // 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. 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. public Card(String suit, int value) { this.suit = suit; this.value = value; } // Returns the suit of this card public String getSuit() { return this.suit; } // Returns the value of this card public int getValue() { return this.value; } // Returns true if the given card has the same suit and value, false otherwise public boolean equals(Card other) { return this.suit.equals(other.suit) && this.value == other.value; } // Returns a String representation of this card // Example: The Jack of Clubs would return "[C 11]" 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; } } }