The Card class, shown below, represents a playing card.

public class Card
{
    /** A single character string representing the suit ("D", "H", "S", or "C") */
    private String suit;

    /** The value (1 - 13 corresponding to Ace, 2 - 10, Jack, Queen, King) */
    private int value;
    
    /**
     * Constructs a playing card with the specified suit and value
     * @param suit one of "D", "H", "S", "C"
     * @param value 1 - 13 corresponding to Ace, 2 - 10, Jack, Queen, King
     */
    public Card(String suit, int value)
    {
        this.suit = suit;
        this.value = value;
    }
    
    /**
     * Returns this card's suit ("D", "H", "S", or "C")
     * @return this card's suit
     */
    public String getSuit()
    {
        return suit;
    }
    
    /**
     * Returns this card's value (1 - 13 corresponding to Ace, 2 - 10, Jack, Queen, King)
     * @return this card's value
     */
    public int getValue()
    {
        return value;
    }

    /**
     * Returns this card with the 1 or 2 character value (A, 2 - 10, J, Q, K)
     * followed by the 1 character suit (D, H, S, C)
     * Examples: "JD", "10H", "AS", "9C"
     */
    public String toString()
    {
        String name = "";
        
        int v = getValue();
        
        if(v == 1)
            name += "A";
        else if(v == 11)
            name += "J";
        else if(v == 12)
            name += "Q";
        else if(v == 13)
            name += "K";
        else
            name += v;
        
        name += getSuit();
        
        return name;
    }
}

You will write TrickCard, which is a subclass of Card.

A TrickCard has a fake value that is treated as the card’s value until it is removed.

The TrickCard class contains an additional method, removeFakeValue, that reverts the card to its true value.

The following table contains a sample code execution sequence and the corresponding results. The code execution sequence appears in a class other than Card or TrickCard.

Statement Return value (blank if no value) Explanation
TrickCard tc =
    new TrickCard("H", 1, 4);
Constructs a TrickCard with a suit of hearts, a true value of ace (1), and a fake value of 4
tc.getSuit(); "H" The suit is hearts. The suit is never faked.
tc.getValue(); 4 The fake value is 4.
tc.toString(); "4H" The toString computation uses the fake value.
tc.removeFakeValue(); The fake value of 4 is removed. The card reverts to its true value of ace (1).
tc.getSuit(); "H" The suit remains hearts.
tc.getValue(); 1 The card now shows its true value of ace (1).
tc.toString(); "AH" The toString computation now uses the true value.

Write the complete TrickCard class. Your implementation must meet all specifications and conform to the examples shown in the preceding table.

The TrickCard class must not duplicate state or behavior from Card.

Solution & comments

See the TrickCard solution or review it with AP CS Tutor Brandon Horn.

Comment on TrickCard