Adding the Remaining Class

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

The class is completed below.

Adding the Remaining 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.

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 ;
  }
}

The calculateTax() method must be made public.

QUESTION 12:

Can another class implement the Taxable interface?