2005 Tickets

<< 2005 Hotel | APQuestionsTrailIndex | 2005Average >>

Question from the College Board

Ticket

public abstract class Ticket {


private int serialNumber;

public Ticket()

{ serialNumber= getNextSerialNumber(); }

public abstract double getPrice();

public String toString()
{  return "\nNumber: " + serialNumber + "\nPrice: " + getPrice();}

private static int getNextSerialNumber()
{ return (int)(Math.random()*10000); }


}

Advance


public class Advance extends ???{



}

StudentAdvance

public class StudentAdvance extends ??? {


}

A class to test out the Ticket Stuff


public class TicketTester
{

	public static void main(String[] args)
	{
		Advance late=new Advance(2);
		Advance ok=new Advance(10);
		StudentAdvance lateStudent=new StudentAdvance(2);
		StudentAdvance okStudent=new StudentAdvance(10);
		System.out.println("Late price (should be 40): "+late);
		System.out.println("adv price (should be 30): "+ok);
		System.out.println("Late Student price (should be 20): "+lateStudent);
		System.out.println("Student advance price (should be 15): "+okStudent);
	}


}