Inheritance hierarchy practice
Before we move on to bigger, more real things, let’s take a moment to think about designed in a somewhat contrived context. Build an inheritance hierarchy to model types of tickets to a school dance. Each ticket has a unique number and a price. There are three types of tickets: walk-up tickets, advance tickets, and student advance tickets.
- Walk-up tickets are purchased the day of the event and cost $50
- Advance tickets purchased 10 or more days before the event cost $30, and advance tickets purchased fewer than 10 days before the event cost $40.
- Student advance tickets are sold at half the price of normal advance tickets. When they are purchased 10 or more days early they cost $15, and when they are purchased fewer than 10 days early they cost $20.
All tickets should be able to:
- Be constructed with an initial ticket number
- Give the ticket’s price
- Be represented as a String: “Number: 17, Price: 50.0″
Advance tickets and advance student tickets are constructed with a ticket number and with the number of days in advance that the ticket was purchased. When student advance tickets are printed, the String mentions that the student must show ID (“Number: 17, Price: 15.0 (ID Required)”).