/**
 * An encapsulation of a card in a deck of "playing cards".
 *
 * A card has a suit ("Clubs", "Diamonds", "Hearts" or "Spades") and
 * a value ("2", "3", ..., "10", "Jack", "Queen", "King", or "Ace")
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 * @author  Prof. Nancy Harris, James Madison University
 * @version 1.1 - added equals method
 */
public class Card
{
    private final int              suit, value;



    public static final int CLUBS    = 0;
    public static final int DIAMONDS = 1;
    public static final int HEARTS   = 2;
    public static final int SPADES   = 3;

    public static final int JACK     = 11;
    public static final int QUEEN    = 12;
    public static final int KING     = 13;
    public static final int ACE      = 14;

    private static final String[] suits = {"Clubs","Diamonds",
					   "Hearts","Spades"};


    private static final String[] values = {"","","2","3","4","5","6","7",
					    "8","9","10","Jack","Queen",
					    "King","Ace"};

    /**
     * Explicit Value Constructor
     *
     * @param suit  The suit  (CLUBS, DIAMONDS, HEARTS, SPADES)
     * @param value The value (2, 3, ... 10, JACK, QUEEN, KING, ACE)
     */
    public Card(int suit, int value)
    {
	boolean       ok;
	

	ok         = true;

	// Validate the suit
	if ((suit >= CLUBS) && (suit <= SPADES))
	{
	    this.suit = suit;
	}
	else
	{
	    ok        = false;
	    this.suit = -1;
	}

	// Validate the value
	if ((value >= 1) && (value <= ACE))
	{
	    this.value = value;
	}
	else
	{
	    ok         = false;
	    this.value = -1;
	}
    }

    /**
     * Compares two Card objects for exact equality
     *
     * @return true if suit and value match for both cards, false otherwise
     */
    public boolean equals(Card otherCard)
    {
	boolean result;
	result = false; // default, most will not be equal
	
	if (this.suit == otherCard.suit) // integers 
		if (this.value == otherCard.value)
			result = true;
	
	return result;
    }

    /**
     * Get a String representation of the suit of this Card
     *
     * @return "Clubs", "Diamonds", "Hearts" or "Spades"
     */
    public String getSuit()
    {
	return suits[suit];
    }


    /**
     * Get a String representation of the value of this Card
     *
     * @return "2", "3", ..., "10", "Jack", "Queen", "King", or "Ace"
     */
    public String getValue()
    {
	return values[value];
    }


    /**
     * Return a formatted String representation of this
     * Card (that contains the suit and value)
     *
     * @return  The String representation of this Card
     */
    public String toString()
    {
	return (getValue() + " " + getSuit());
    }
}
