package oving5.card; public class Card implements Comparable { private String suit; private int face; /* * Constructor used to create a new instance of Card. * * @param suit The suit of the card, ("H", "S", "D", "C"). * @param face The face of the card, ("1","2","3", ... "13"). */ public Card(String suit, int face) { this.suit = suit; this.face = face; } /* * @return The suit of the card. */ public String getSuit() { return this.suit; } /* * @return The face of the card. */ public int getFace() { return this.face; } /* * @return The suit and face of the card in a String, for e.g. "S2" or "H3". */ public String toString() { return this.suit + this.face; } /* * @return The index (value) of the suit as an Integer. */ private int getSuitValue() { return "CDSH".indexOf(getSuit()); } /* * If the card is an Ace (at position 14), then return 1. If not return the value of the face+1. * * @return The value of the face. */ private int getFaceValue() { return (face == 14 ? 1 : face+1); } /* * Compares two cards. * * @return A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified Card object. */ public int compareTo(Card c) { if (this.face == c.face) { return getSuitValue() - c.getSuitValue(); } else { return getFaceValue() - c.getFaceValue(); } } }