Question 3

public class StandardTicket {

public static int WINDOW = 1, AISLE = 2; // constants

private int seatPosition; // =1 if a window seat, =2 if an aisle seat

protected int age; // age in years of tourist buying ticket

public StandardTicket (int seatPosn, int ageInYears) {

seatPosition = seatPosn;

age = ageInYears;

}

public double cost () {

if (seatPosition == WINDOW) return 30.0;

else return 22.5;

}

public String toString () {

String info;

if (seatPosition == WINDOW) info = "("+age+") window seat: $";

else info = "("+age+") aisle seat: $";

return info+cost();

}

}

 

 

 

~~~~~~~

 

public class DeluxeTicket extends StandardTicket {

public static int HOT = 1, COLD = 2; // constants

private int lunchType; // =1 if hot lunch, =2 if cold lunch

public DeluxeTicket (int typeOfLunch, int ageInYears) {

super(WINDOW, ageInYears);

lunchType = typeOfLunch;

}

public double cost () {

double base = super.cost();

if (lunchType == HOT) base = base + 12.50;

else base = base + 7.50;

if (age> 55) base = 0.95 * base;

return ((int)(base * 100))/100.0;

}

public String toString () {

String tmp;

if (lunchType == HOT) tmp = "hot lunch";

else tmp = "cold lunch";

return tmp+" "+super.toString();

}

/* Question 2b:

introduce a static int variable count in this class.

It should be initialised to zero.

Each ime the constructor is called, this variable is

incremented.

At any time it indicates the number of DeluxTickets

have been issued.

*/

}

 

 

 

~~~~~~~~~~~