// CMPU-101-51, Spring 2007
// Asmt 8

// The Card class (designed in class on April 16)

class Card {
  
  // -----------------------
  //  class-oriented data
  // -----------------------
  
  static String[] suits = {"club", "diamond", "heart", "spade"};
  static String[] ranks = {"ace", "2", "3", "4", "5", "6", "7",
    "8", "9", "10", "jack", "queen", "king"};
  
  // -----------------------
  //  object-oriented data 
  // -----------------------
  
  // the numerical representation of a card (a number from 0 to 51)
  private int num; 
    
  // -------------------
  //  constructor
  // -------------------
  //   Takes a numerical value as an input, which is used to set
  //   the value of the "num" field.
  
  Card(int id) {
    this.num = id;
  }
  
  // ---------------------------
  //   object-oriented methods
  // ---------------------------
  
  //  isAce
  // --------------
  //  returns true if this card is an ace
  
  boolean isAce() {
    return (num%13 == 0);   
  }
    
  //  value
  // ----------------
  //  returns the value of the card according to the rules
  //  of blackjack:
  //      the value of an ace is 1
  //      each card from 2 through 9 has a value equal to its rank
  //         (i.e., 2 thru 9)
  //      the value of a 10, J, Q or K is 10
 
  int value() {
    if (num%13 >= 9) return 10;
    else return num%13 + 1;
  }
  
  //  intSuit
  // ------------------------------
  //  Helper function for getting index into the "suits" array.
  //  Returns a number in the range 0, 1, 2, or 3
  
  int intSuit() {
    return num/13;
  }
  
  //  intRank  (formerly called intValue)
  // ---------------------------------------
  //   Helper function for getting index into the "rank" array.
  //   Returns a number in the range 0, 1, 2, ..., 12
  
  int intRank() {
    return num%13;
  }
  
  //  toString
  // -------------------------
  //  generate a string representation of the Card
  
  public String toString() {
    return Card.ranks[this.intRank()] + " of " 
      + Card.suits[this.intSuit()] + "s";  
  }
  
}