Other 2005 FR Questions FR other years Be Prepared Home
A-2
Part (a)
public class Advance extends Ticket
{
  private int daysInAdvance;

  public Advance (int days)
  {
    daysInAdvance = days;
  }

  public double getPrice()
  {
    if (daysInAdvance >= 10)
      return 30.0;
    else
      return 40.0;
  }
}

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

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

  public String toString()
  {
    return super.toString() + " (student ID required)"; 2
  }
}
Notes:
  1. Do not define new fields in this class.  The daysInAdvance field is already defined in Advance.

  2. Reuse the code in Advance's toString.

Other 2005 FR Questions | Back to Contents

Copyright © 2005 by Skylight Publishing
support@skylit.com