
/* 
   An object belonging to the class Card represents a playing card.
   with a suit (clubs, hearts, spades, or diamonds) and a value (ace,
   jack, queen, king, or one of the numbers 2 thrugh 10).  The
   suit is represented by an integer between 0 and 3, and the value
   is represented by an integer between 0 and 12.  Note that, unfortunately,
   the value of an ACE is 0, the value of a TWO is 1, etc.
*/


public class Card {


   public final static int CLUBS = 0,     // int constants that represent
                           HEARTS = 1,    //    the possible suits
                           SPADES = 2,
                           DIAMONDS = 3;


   public final static int ACE = 0,       // int constants that represent
                           JACK = 10,     //     some possible values
                           QUEEN = 11,
                           KING = 12;


   // provide strings to name all the suits and values:

   public final static String[] suitName = { "Clubs", "Hearts", "Spades", "Diamonds" };

   public final static String[] valueName = { "Ace", "2", "3", "4", "5", "6", "7", "8",
                                        "9", "10", "Jack", "Queen", "King" };
 

   private int suit, value;  // the actual suit and value of this card


   public Card(int suit, int value) {
         // Constructor produces a card with the specified suit and
         // value.  If suit and/or value are not in the valid ranges
         // 0 to 3 and 0 to 12, then the result is unpredictable but
         // will represent SOME valid card.
      this(13*suit + value);
   }


   public Card(int cardCode) {
         // Cards are conceptually numbered from 0 to 51.  This constructor
         // takes a sequence number in that numbering and makes the corresponging
         // card.  If cardCode is not in the range 0 to 51, the result is
         // unpredicatable but will represent SOME valid card.
      cardCode = Math.abs(cardCode % 52);  // make sure cardCode is in range 0 to 51
      value = cardCode % 13;
      suit = cardCode / 13;
   }


   public int getValue() {  // returns the value of this card
      return value;
   }


   public int getSuit() {   // returns the suit of this card
      return suit;
   }


   public String toString() {  // returns a String representation of this card
      return valueName[value] + " of " + suitName[suit];
   }


}  // end class Card



