Question: a) (9 points) Write the class Ticket with exactly one instance field (you can have one static field as well) that is private int: The

a) (9 points) Write the class Ticket with exactly one instance field (you can have one static field as well) that is private int: The field should be named serialNumber. Create a no- argument constructor in this class. In the constructor, generate and store a unique value into the serialNumber field. The serial number for the first Ticket object must be 1 and the serial number must increase by 1 for every successive instances of Ticket. Create a getter for serialNumber. The class must have an abstract method named getPrice(), which returns a double. (Every ticket is required to return its price.) Note that there is no, field for price. Override toString() to return a message such as the following: Ticket 85 price 38.5 That is, the string has the word Ticket, followed by the serial number, then the word price, and then the price itself. The additional classes are as described below. price, and then the price itself The additional classes are as described below. Cluss Description Sample toString output Advance A type of Ticket. If Ticket 34 price 35 purchased 10 or more days in advance, the cost is $35; if purchased less than 10 days in advance, but before the day of the event, the cost of $45. Otherwise, the cost is $50 (not really an advance ticket). These costs could change. StudentAdvance A type of Advance and costs Ticket 11 price 17.5 half of what an Advance ticket costs b) (Spoints) Write the complete declarations for the class Advance. Include all necessary instance variables and methods. The constructor should take as its only parameter, the number of days in advance that this ticket is being purchased. You cannot change the Ticket class. c) (8 points) Write the complete declarations for the class StudentAdvance. Include all necessary instance variables and methods. The constructor should take as its only parameter, the number of days in advance that this ticket is being purchased. The toString method should return not only what the Ticket class returns, but an additional reminder that student id should be produced at the gate. The methods should continue to work - with no modification necessary - even if prices are changed in the Advance class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
