public class Card
{
  public int suit, rank;

  public Card () { 
    this.suit = 0;  this.rank = 0;
  }

  public Card (int suit, int rank) { 
    this.suit = suit;  this.rank = rank;
  }

  public static void printCard (Card c) {
    String[] suits = { "Clubs", "Diamonds", "Hearts", "Spades" };
    String[] ranks = { "narf", "Ace", "2", "3", "4", "5", "6",
		 "7", "8", "9", "10", "Jack", "Queen", "King" };

    System.out.println (ranks[c.rank] + " of " + suits[c.suit]);
  }

  // compareCards: returns -1 if the first card is less than the
  // second, 1 if it is greater, and 0 if they are the same.

  // in this case, contrary to the way it appears in the book,
  // rank is more important than suit.

  public static int compareCards (Card c1, Card c2) {

    // first we use modulus arithmetic to rotate the ranks
    // so that the Ace is greater than the King.
    
    int rank1 = (c1.rank + 11) % 13;
    int rank2 = (c2.rank + 11) % 13;

    // compare the rotated ranks

    if (rank1 > rank2) return 1;
    if (rank1 < rank2) return -1;

    // if the ranks are the same, compare the suits

    if (c1.suit > c2.suit) return 1;
    if (c1.suit < c2.suit) return -1;

    return 0;
  }
	
  public static void main (String[] args) {
    Card card1 = new Card (2, 11);
    Card card2 = new Card (1, 1);

    int comp = compareCards (card1, card2);
    String s;

    if (comp > 0) {
      s = "is greater than";
    } else if (comp < 0) {
      s = "is less than";
    } else {
      s = "is the same as";
    }

    printCard (card1);
    System.out.println (s);
    printCard (card2);
  }
}
