Assignment #2: Basic Inheritance

A set of classes is used to handle the different ticket types for a theater. All tickets have a unique serial number that is assigned when the ticket is constructed and a price. There are three basic types of tickets:
Ticket type Description Sample toString Output
WalkupTicket These tickets are purchased on the day of the event for $50 SN: 314, $50
AdvanceTicket Tickets purchased ten or more days in advance cost $30. Tickets purchased fewer than ten days in advance cost $40. SN: 612, $40
StudentAdvanceTicket These are AdvanceTickets that cost half of what an AdvanceTicket would normally cost. SN: 59, $15 (student)
  1. Design a class hierarchy that encompasses the above three classes, and adds an abstract class called Ticket.
  2. Implement the Ticket abstract class. This class should store a serial number as its private data, and the constructor should initialize the serial number. Also keep a static variable lastSerialNumber that can keep track of the last serial number assigned (so you can avoid duplicates). Provide an appropriate abstract method (HINT: what can ALL tickets do?), and also provide an implementation of toString that prints the serial number and price information.
  3. Implement the WalkupTicket class.
  4. Implement the AdvanceTicket class. Provide a constructor that takes a parameter indicating the number of days in advance that the ticket is being purchased. Recall that the number of days of advanced purchase affects the ticket price.
  5. Implement the StudentAdvanceTicket class. Provide a constructor that takes a parameter indicating the number of days in advance that the ticket is being purchased. The toString method should include a notation that this is a student ticket. This ticket costs have of an Advanceticket. If the pricing scheme for AdvanceTicket changes, the StudentAdvanceTicket price should be computed correctly with no code modification to the StudentAdvanceTicket class.
  6. Provide a test program that populates an array of Ticket with all three kinds of tickets, and then calls a function that computes the total cost of all the tickets in the array.