/** * A Card object represents a single playing card, with a rank and suit. * * @author Dave Reed * @version 11/25/04 */ public class Card { private char rank; private char suit; /** * Creates a card with the specified rank and suit * @param cardRank one of '2', '3', '4', ..., '9', 'T', 'J', 'Q', 'K', or 'A' * @param cardSuit one of 'S', 'H', 'D', 'C' */ public Card(char cardRank, char cardSuit) { rank = cardRank; suit = cardSuit; } /** * Accessor method * @return the rank of the card (e.g., '5' or 'J') */ public char getRank() { return rank; } /** * Accessor method * @return the suit of the card (e.g., 'S' or 'C') */ public char getSuit() { return suit; } /** * Accessor method * @return a string consisting of rank followed by suit (e.g., "2H" or "QD") */ public String toString() { return "" + rank + suit; } /** * Comparison method * @return true if other is a Card with the same rank and suit, else false */ public boolean equals(Object other) { try { Card otherCard = (Card)other; return (getRank() == otherCard.getRank() && getSuit() == otherCard.getSuit()); } catch (ClassCastException e) { return false; } } }