/** This is the playing card class. Its 2 attributes are denomination * and suit, which are both char. For the sake of completeness, we have * included 3 constructors: default, initial value and copy, although * the i.v. constructor is the most useful in this program. * One noteworthy thing about this class is that we have so many functions * returning boolean -- basically we are just asking yes/no questions about * the Card object. */ public class Card { private char denom; private char suit; /** default constructor -- just initialize to Q-d */ public Card() { denom = 'Q'; suit = 'd'; } /** Initial value constructor -- given 2 parameters that specify * what the denomination and suit should be, just initialize */ public Card(char d, char s) { denom = d; suit = s; } /** Copy constructor -- make a duplicate of an existing card, * We do not anticipate this constructor being used much, but it's * good practice. */ public Card(Card c) { denom = c.denom; suit = c.suit; } //---------------------------------------------------------------- /** isSameSuit() will return true or false depending on whether * the two cards are in the same suit or not. */ public boolean isSameSuit(Card c) { return (this.suit == c.suit); } /** isSameValue() is analogous: we compare denominations */ public boolean isSameValue(Card c) { return (this.denom == c.denom); } /** isOneHigherThan(). This function will be useful when we want * to detect a straight. See if I am 1 higher than the 2nd card * (the parameter). For example we would return true if we had * this = 'J' and parameter = 'T'. */ public boolean isOneHigherThan(Card c) { if (this.denom == 'A' && c.denom == 'K') return true; else if (this.denom == 'K' && c.denom == 'Q') return true; else if (this.denom == 'Q' && c.denom == 'J') return true; else if (this.denom == 'J' && c.denom == 'T') return true; else if (this.denom == 'T' && c.denom == '9') return true; else if (this.denom == 1 + c.denom) return true; else if (this.denom == '2' && c.denom == 'A') return true; else return false; } /** isFaceCard() and other similar functions are not really needed in * the poker program, but are included here so you can see some variety. */ public boolean isFaceCard() { return (this.denom == 'J' || this.denom == 'Q' || this.denom == 'K'); } /** isRed() -- The red cards are diamonds and hearts. */ public boolean isRed() { return (this.suit == 'd' || this.suit == 'h'); } /** We already have a way of determining if a card is red, so we simply * call isRed(), and return the opposite answer. */ public boolean isBlack() { return (! this.isRed()); } /** Having an isAce() function is useful when we want to tell if a * straight flush is ace high: then it's a royal flush. */ public boolean isAce() { return (this.denom == 'A'); } }