Question: In your text, Building Java Programs, 5th Edition, in Chapter 9, starting on page 662 (eBook; printed text is the same), please work exercises 5,



5. For the next four problems, consider the task of representing types of tickets to campus events. Each ticket has a unique number and a price. There are three types of tickets: walk-up tickets, advance tickets, and student advance tickets. Figure 9.10 illustrates the types: Figure 9.10 Classes of tickets that are available to campus events Ticket number Ticket(number) getPrice toStringo Walkup Ticket Advance Ticket Student Advance Ticket 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 ad- vance 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 pur- chased fewer than 10 days early they cost Implement a class called Ticket that will serve as the superclass for all three types of tickets. Define all common operations in this class, and specify all differing operations in such a way that every subclass must imple- ment them. No actual objects of type Tick- et will be created: Each actual ticket will be an object of a subclass type. Define the fol- lowing operations: The ability to construct a ticket by number. The ability to ask for a ticket's price. The ability to println a ticket object as a String. An example String would be "Number: 17, Price: 50.0". 6. Implement a class called WalkupTicket to represent a walk-up event ticket. Walk-up tickets are also constructed by number, and they have a price of $50. 7. Implement a class called AdvanceTicket to represent tickets purchased in advance. An advance ticket is constructed with a ticket number and with the number of days in ad- vance that the ticket was purchased. Ad- vance tickets purchased 10 or more days be- fore the event cost $30, and advance tickets purchased fewer than 10 days before the event cost $40. 6. Implement a class called WalkupTicket to represent a walk-up event ticket. Walk-up tickets are also constructed by number, and they have a price of $50. 7. Implement a class called AdvanceTicket to represent tickets purchased in advance. An advance ticket is constructed with a ticket number and with the number of days in ad- vance that the ticket was purchased. Ad- vance tickets purchased 10 or more days be- fore the event cost $30, and advance tickets purchased fewer than 10 days before the event cost $40. 8. Implement a class called StudentAd- vanceTicket to represent tickets pur- chased in advance by students. A student advance ticket is constructed with a ticket number and with the number of days in ad- vance that the ticket was purchased. Student advance tickets purchased 10 or more days before the event cost $15, and student ad- vance tickets purchased fewer than 10 days before the event cost $20 (half of a normal advance ticket). When a student advance ticket is printed, the String should mention that the student must show his or her student ID (for example, "Number: 17, Price: 15.0 (ID required)")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
