Question: Objectives To practice with OOP principles in Java Task A set of classes is used to handle the different ticket types for a theater. All
Objectives
- To practice with OOP principles in Java
Task
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 many types of tickets.
| Ticket type | Description | Sample toString output |
| Ticket | This is an abstract class representing all tickets | |
| FixedPriceTicket | This is an abstract class representing tickets that are always the same price. The constructor accepts the price as the parameter. | |
| ComplimentaryTicket | These tickets are free (thus FixedPrice). | SN: 273, $0 |
| WalkupTicket | These tickets are purchased on the day of the event for $50 (thus FixedPrice). | 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) |
Your task is to:
- Design a class hierarchy that encompasses the above three classes.
- Implement the Ticket abstract class. This class should store an integer serial number as its private data. Provide int getPrice() abstract method to get the price of the ticket, provide int getSN() method that returns the serial number, and provide an implementation of toString that prints the serial number and price information. The Ticket class must provide a constructor to initialize the serial number. To do so, use the following strategy: maintain a static ArrayList
representing previously assigned serial numbers. Repeatedly generate a new serial number(between 0-10000) using a random number generator until you obtain a serial number not already assigned. - Implement the FixedPriceTicket class. The constructor accepts a price. The class is abstract but you can and should implement the method that returns the price information.
- Implement the WalkupTicket class and the ComplementaryTicket class.
- 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.
- 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 half 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.
- Write a class TicketOrder that stores a collection of Tickets. TicketOrder should provide methods add, toString, and totalPrice. add method should add an instance of the non-abstract ticket types to the collection and return true or false, depending on the success of the operation. toString should return a string representation of all tickets in the collection(should call the toString method for each ticket). The totalprice method should return an int which is the sum of the prices of all tickets in the collection.
A driver program Main.java
has been included. It is an example test program that creates a TicketOrder and calls add on all kinds of tickets. It then prints the order and total price. However, your classes will be tested with more than just this sample driver. It is recommended that you write other driver programs of your own, for more thorough testing. Here is the output
of this test program based on my implementation.
Main.java
class Main {
public static void main(String[] args) {
TicketOrder t = new TicketOrder();
t.add(new ComplementaryTicket());
t.add(new AdvanceTicket(2));
t.add(new AdvanceTicket(20));
t.add(new StudentAdvanceTicket(2));
t.add(new StudentAdvanceTicket(20));
t.add(new WalkupTicket());
System.out.println(t);
System.out.println("total: $"+t.totalPrice());
}
}
OUTPUT
SN: 9828, $0
SN: 6951, $40
SN: 5616, $30
SN: 6659, $20(student)
SN: 8099, $15(student)
SN: 4576, $50
total: $155
General Requirements
- Document your code appropriately so that it is readable and easy to navigate
- If I can't compile your code without your presence, you won't get any credits for this or any other projects. Compile and test your code on at least one other machine (preferably lab machines) before submitting. Projects with compile errors won't be graded.
Submission
These are the deliverable files you should submit:
AdvanceTicket.java ComplementaryTicket.java FixedPriceTicket.java StudentAdvanceTicket.java Ticket.java TicketOrder.java WalkupTicket.java
General Requirements
- Document your code appropriately so that it is readable and easy to navigate
- If I can't compile your code without your presence, you won't get any credits for this or any other projects. Compile and test your code on at least one other machine (preferably lab machines) before submitting. Projects with compile errors won't be graded.
Submission
These are the deliverable files you should submit:
AdvanceTicket.java ComplementaryTicket.java FixedPriceTicket.java StudentAdvanceTicket.java Ticket.java TicketOrder.java WalkupTicket.java
Transcribed image text
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
