Item
free response problem from the 2006 AP Computer Science A Exam
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.