/**
 * A specialized Card that can be compared to another
 * PlayingCard (i.e., a specialization of the Card class
 * that implements the Comparable interface)
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class PlayingCard extends Card implements Comparable
{
    /**
     * Explicit Value Constructor
     *
     * @param suit   The suit of the card
     * @param value  The value of the card
     */
    public PlayingCard(int suit, int value)
    {
		super(suit, value);
    }

    /**
     * Compare this PlayingCard to another PlayingCard
     * (required by Comparable)
     *
     * @param otherObject   The other PlayingCard
     */
     public int compareTo(Object otherObject)
     {
			Card     other;
			int      comparison, otherPoints, thisPoints;
			String   otherSuit, otherValue, thisSuit, thisValue;

			other = (Card)otherObject;

			thisSuit    = this.getSuit();
			thisValue   = this.getValue();
			thisPoints  = getIntForValue(thisValue);

			otherSuit   = other.getSuit();
			otherValue  = other.getValue();
			otherPoints = getIntForValue(otherValue);

			comparison = 0;
			if  (thisPoints > otherPoints)
			{
	    		comparison = 1;
			}
			else 
				if (thisPoints < otherPoints)
				{
	    			comparison = -1;
				}
				else
				{
	   			 thisPoints  = getIntForSuit(thisSuit);
	    			 otherPoints = getIntForSuit(otherSuit);

	    			 if (thisPoints > otherPoints)
	    			 {
							comparison = 1;
	    			 }
	    			 else 
					     if (thisPoints < otherPoints)
	    				  {
								comparison = -1;
	    				  }
		}

			return comparison;
   }


    /**
     * Get an int that can be used for comparing
     * suits
     *
     * Suits are ordered as follows:
     *
     *     Spades > Clubs > Diamonds > Hearts)
     *
     * @param theSuit   The suit of the card
     */
    private int getIntForSuit(String theSuit)
    {
	int    points;

	points = 0;
	if (theSuit.equalsIgnoreCase("Spades"))
	{
	    points = 4;
	}
	else if (theSuit.equalsIgnoreCase("Clubs"))
	{
	    points = 3;
	}
	else if (theSuit.equalsIgnoreCase("Diamonds"))
	{
	    points = 2;
	}
	else if (theSuit.equalsIgnoreCase("Hearts"))
	{
	    points = 1;
	}

	return points;
    }



    /**
     * Get an int that can be used for comparing
     * values
     *
     * Values are ordered as follows:
     *
     *     Ace > King > Queen > Jack > 10 > ... > 3 > 2
     *
     * @param theValue    The value of the card
     */
    private int getIntForValue(String theValue)
    {
	int           points;

	points = 0;
	try {

	    points = Integer.parseInt(theValue);

	} catch (NumberFormatException nfe) {

	    if      (theValue.equalsIgnoreCase("Jack"))
	    {
		points = 11;
	    }
	    else if (theValue.equalsIgnoreCase("Queen"))
	    {
		points = 12;
	    }
	    else if (theValue.equalsIgnoreCase("King"))
	    {
		points = 13;
	    }
	    else if (theValue.equalsIgnoreCase("Ace"))
	    {
		points = 14;
	    }
	}

	return points;
    }
}
