Ticket is #2 from the from the 2005 AP Computer Science A Free Response problems.

https://secure-media.collegeboard.org/apc/_ap05_frq_comp_sci_a_45544.pdf

Part (a) Advance class

public class Advance extends Ticket
{
    private double price;

    public Advance(int days)
    {
        super();

        if (days >= 10)
            price = 30;
        else
            price = 40;
    }

    public double getPrice()
    {
        return price;
    }
}

See Class writing order for a technique to respond to AP CS FR that request an entire class.

See Inheritance and polymorphism for details including how to write subclasses.

Part (b) StudentAdvance class

public class StudentAdvance extends Advance
{
    public StudentAdvance(int days)
    {
        super(days);
    }

    public double getPrice()
    {
        return super.getPrice() / 2;
    }

    public String toString()
    {
        return super.toString() + "\n(student ID required)";
    }
}

2005 AP CS Exam Free Response Solutions

Additional inheritance & polymorphism resources

Help & comments

Get help from AP CS Tutor Brandon Horn

Comment on Ticket