// An alternate playing card class // Kim Bruce, 2/9/04 public class OtherCard extends AbsCard { protected int number; // single letter encoding of card // post: Constructs a card with default value "Ace of Spades" public OtherCard() { this(ACE,SPADES); } // post: Constructs a card of the given type public OtherCard(int theRank, int theSuit) { number = 13*theSuit + theRank -2; } // post: returns hash code for this card public int hashCode() { return number; } // post: returns suit of card public int getSuit() { return number / 13; } // post: returns rank of card public int getRank() { return number % 13 + 2; } // Test Card class public static void main(String args[]) { // Create some cards CardInterface first = new OtherCard(THREE,DIAMONDS); CardInterface second = new OtherCard(); System.out.println(); System.out.println(first); System.out.println(second); System.out.println(); System.out.print("These cards are "); if(!first.equals(second)) System.out.print("not "); System.out.println("equal"); System.out.println(); // Create an array of cards CardInterface[] hand = new CardInterface[5]; hand[0] = new OtherCard(ACE,HEARTS); hand[1] = new OtherCard(KING,HEARTS); hand[2] = new OtherCard(QUEEN,HEARTS); hand[3] = new OtherCard(JACK,HEARTS); hand[4] = new OtherCard(TEN,HEARTS); for(int i=0;i<4;i++) { System.out.print(hand[i] + ", "); } System.out.println(hand[4]); } }