// Arup Guha
// 9/12/02
// Brief Description: The card class defines a card object to store 
//                    information about a playing card. The information
//                    supported is the suit and type of card, as well as
//                    the value in the game of bridge of that card.
public class card {

  private String suit;
  private String type;
  private int abs_rank;
  private int value;

  // Constructor, directly assigns the sign and suit, and must 
  // initialize the other two instance variables.
  public card(String s, String k) {

    suit = s.toLowerCase();
    type = k.toLowerCase();

    // Helps compute the value and rank of the card.
    if (type.equals("ace")) 
      abs_rank = 14;
    else if (type.equals("king"))
      abs_rank = 13;
    else if (type.equals("queen"))
      abs_rank = 12;
    else if (type.equals("jack"))
      abs_rank = 11;
    else if (type.equals("ten"))
      abs_rank = 10;
    else if (type.equals("nine"))
      abs_rank = 9;
    else if (type.equals("eight"))
      abs_rank = 8;
    else if (type.equals("seven"))
      abs_rank = 7;
    else if (type.equals("six"))
      abs_rank = 6;
    else if (type.equals("five"))
      abs_rank = 5;
    else if (type.equals("four"))
      abs_rank = 4;
    else if (type.equals("three"))
      abs_rank = 3;
    else
      abs_rank = 2;

    // Calculates the bridge value of the card from the computed rank.
    if (abs_rank <= 10)
      value = 0;
    else
      value = abs_rank % 10;
    
    // Assigns an unique rank for each possible playing card.
    int temp=0;
    if (suit.equals("diamonds"))
      temp = 1;
    else if (suit.equals("hearts"))
      temp = 2;
    else if (suit.equals("spades"))
      temp = 3;
  
    abs_rank = 13*temp + (abs_rank - 1);

  }

  // Accessor methods.
  public int getvalue() {
    return value;
  }

  public String getsuit() {
    return suit;
  }

  public String gettype() {
    return type;
  }

  public int getrank() {
    return abs_rank;
  }

  // Compares two playing cards. Returns a positive number if the first
  // card is greater than the second, 0 if they are equal, and negative
  // if the first card is less than the second card.
  public int compareTo(card other) {
    return abs_rank - other.abs_rank;
  }

  public String toString() {
    return (type+" of "+suit);
  }

}
