Item is #2 from the from the 2006 AP Computer Science A Free Response problems.

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

Part (a) purchasePrice method

public double purchasePrice()
{
    double tax = getListPrice() * taxRate;
    return getListPrice() + tax;
}

Part (b) Vehicle class

public class Vehicle extends TaxableItem
{
    private double cost, markup;
    
    public Vehicle(double cost, double markup, double taxRate)
    {
        super(taxRate);
        this.cost = cost;
        this.markup = markup;
    }
    
    public double getListPrice()
    {
        return cost + markup;
    }
    
    public void changeMarkup(double newMarkup)
    {
        markup = newMarkup;
    }
}

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.

2006 AP CS Exam Free Response Solutions

Additional inheritance & polymorphism resources

Help & comments

Get help from AP CS Tutor Brandon Horn

Comment on Item