
/* 
   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 1 and 4, and the value
   is represented by an integer between 1 and 13, where 1 is an ACE,
   11 is a Jack, 12 is a Queen, and 13 is a King.
*/

public class Card {


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


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


   // 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
         // 1 to 4 and 1 to 13, then the result is unpredictable but
         // will represent SOME valid card.
      this(13*(suit-1) + (value-1));
   }


   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) + 1;
      suit = (cardCode / 13) + 1;
   }


   public int getValue() {  // returns the value of this card as an integer code number
      return value;
   }


   public int getSuit() {   // returns the suit of this card as an integer code number
      return suit;
   }


   public String getValueName() {  // returns the value of this card as a String
      return valueName[value - 1];
   }


   public String getSuitName() {   // returns the suit of this card as a String
      return suitName[suit - 1];
   }


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


}  // end class Card



