D.1.8 Construct related objects for a given problem.
A ticket store is selling tickets for an upcoming concert. All tickets have a ticket number and a price. Though every ticket has a unique ticket number, its default ticket number is 000 and the default price is 50.00. Ticket price may change depending on how many days in advance it's purchased, and if a special privilege is considered to avail a discount.
Each ticket has a unique ticket number that is assigned when the ticket is constructed. For all ticket classes, the toString method returns a string containing the information for that ticket with additional information if needed. Three additional classes are used to represent the different types of tickets and are described in the table below. Carefully examine which method/s need/s to be overridden. Take note of what the toString() method prints.
Using the class hierarchy and specifications given above, you will write the complete class declarations for the EarlyPurchase and StudentEarlyPurchase classes.
Construct related objects from the given problem
Create a UML diagram to visualize your answer
Use abstraction to minimize code duplication
Construct a UML Diagram that represents the Ticket class and all other related classes described in the table above.
Write the complete class declaration for the class EarlyPurchase. Include all necessary instance variables and implementations of the its constructor and method(s). The constructor should take parameters that indicate the ticket number and the number of days in advance that this ticket is being purchased. Tickets purchased ten or more days in advance is 10% discounted; tickets purchased nine or fewer days in advance or early is 5% discounted.
Write the complete class declaration for the class StudentEarlyPurchase. Include all necessary instance variables and implementations of its constructor and method(s). The constructor should take parameters that indicate the ticket number and the number of days in advance that this ticket is being purchased. The toString() method should include a notation that a student “ID is required” for this ticket. A StudentEarlyPurchase ticket costs half of what that EarlyPurchase ticket would normally cost.
Note: If the pricing scheme for EarlyPurchase tickets changes, the StudentEarlyPurchase price should continue to be computed correctly with no code modifications to the StudentEarlyPurchase class.
Ticket is the superclass of Walkin and EarlyPurchase
EarlyPurchase is a superclass of StudentEarlyPurchase
Walkin, EarlyPurchase are subclasses of Ticket
StudentEarlyPurchase is a subclass of EarlyPurchase
StudentEarlyPurchase inherits the public methods and variables of both EarlyPurchase and Ticket classes