public class Card implements Comparable { enum SUIT {CLUBS,DIAMONDS,HEARTS,SPADES}; enum FACE {TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT, NINE,TEN,JACK,QUEEN,KING,ACE}; private SUIT suit; /*property*/ private FACE face; /*property*/ public Card () { } public Card (String aSuit, String aFace) { suit = SUIT.valueOf (aSuit.toUpperCase () ); face = FACE.valueOf (aFace.toUpperCase () ); } public SUIT getSuit () { return suit; } public FACE getFace () { return face; } public String toString(){ return face + " OF " + suit; } public boolean equals ( Object otherObject ) { if (otherObject == null) { System.out.println ("This object cannot be compared to a null reference. Returning false."); return false; } if ( this.getClass() != otherObject.getClass() ) { System.out.println ("The argument is not of "+this.getClass()+" type. Returning false."); return false; } Card other = (Card) otherObject; // SUIT othersSuit = other.getSuit (); SUIT othersSuit = other.suit; FACE othersFace = other.getFace (); return (othersSuit.equals(suit) && othersFace.equals(face)); } public int compareTo ( Object otherObject ) { if (otherObject == null) { System.out.println ("This object cannot be compared to a null reference. Exitting.."); System.exit(0); } if ( this.getClass() != otherObject.getClass() ) { System.out.println ("The argument is not of "+this.getClass()+" type. Exitting.."); System.exit(0); } Card other = (Card) otherObject; SUIT othersSuit = other.getSuit (); FACE othersFace = other.getFace (); int result=1; if (this.equals(other)) result=0; if (face.ordinal() < othersFace.ordinal()) result = -1; else if (face.ordinal() == othersFace.ordinal()) result = suit.ordinal () - othersSuit.ordinal(); return result; } }