go to previous page   go to home page   go to next page

Answer:

The class is completed below.


Adding the Toy Class

The constant taxRate is used in the calculateTax() method just as if it had been defined in the Toy class. Also, it can be used in methods of the class other than those listed in the interface.

The calculateTax() method must be made public.


class Toy extends Goods implements Taxable
{
  int minimumAge;

  Toy( String des, double pr, int min)
  {
    super( des, pr );
    minimumAge  = min ;
  }

  void display()
  {
    super.display() ;
    System.out.println( "minimum age: " + minimumAge );
  }

  public double calculateTax()
  {
    return price * taxRate ;
  }
}

QUESTION 12:

Why must calculateTax() be made public?