Create suitable subclasses of seatreservation called


Programming: Assignment

Place all Java source code.

The goal of this assignment is to create a movie booking system that allows a teller to book Adult, Elderly or Child tickets to different movies using a nicely presented front end GUI. It should keep track of different movies being played, which seats have already been booked and not allow child tickets to be purchased for R rated movies or ensure that a child has to be accompanied by an adult for M rated movies.

Question 1) : Time Class
Using the UML below, create a class that encapsulates integers used to represent hours, minutes and seconds for the time of day in 24 hour format.
- It has four constructors, each passing in different ways a Time object can be created (use a value of 0 for variables not set during construction).
- The class also has getters and setters for each of these fields.
- The Time class should ensure that variables cannot be set below zero or some other invalid value eg: minutes and seconds should only be between 0-59, hours 0-23.
- Create a suitable toString method that prints the time as double digit format. Eg 10:30 pm should return "22:30:00" whereas 12:05 am should return the format "00:05:00".
- Override the equals method of Object so that two Time objects are considered equal if both have hours, minutes and seconds the same.
- The class should also implement the Comparable interface comparing other times so that the earlier time takes precedence. Eg, if this current Time object is earlier in the day than the parameter object then a negative number should be returned.

Question 2) SeatReservation
Prepare an abstract class called SeatReservation for describing an abstract seat booking. It has an abstract method getTicketPrice intended to be overridden by subclasses. It holds a row (char) and column (int) of where the seat is positioned in the movie theatre and a boolean to indicate whether the seat is complementary (free). Create the class following the UML below.

Question 3) SeatReservation subclasses
Create suitable subclasses of SeatReservation called AdultReservation, ChildReservation and ElderlyReservation for allowing the seat to be filled by a child, adult or elderly person. A child class should return the ticket price of $8, whereas an adult ticket should return the ticket price of $12.50. An elderly ticket should return the price which is always %30 off the adult ticket price. However if any of the tickets are complementary, then the price is zero.

Question 4) MovieSession
Using the UML below, create a class called MovieSession which represents a movie with a name, a rating (R, M or G) and a screening time (using the Time class from question 1).
- It also holds a two dimensional array of SeatReservation references called sessionSeats, with null entries indicating that the seat is available otherwise it points to either a valid ElderlyReservation, ChildReservation or AdultReservation depending on the row and col value (where an ‘A' represents an index 0, ‘B' index 1 ect).
- The class also has two static constants used for obtaining the dimensions of the sessionSeats
array.
- It should have suitable getters for obtaining movie information and a suitable toString which prints out the movie name, the rating and the session time.
- The class implements the Comparable interface comparing session times between the two MovieSession instances where an earlier session time should take precedence. If the session time is the same between the two, then use the movie name as a comparison.
- It has two static methods, convertRowToIndex and convertIndexToRow used to convert row letters to an index so that a row and col can be used to refer to the two dimensional array of sessionSeats.

- The isSeatAvailable should return a true if a seat at the specified row and column has not been previously booked (ie is null).
- A getSeat returns the SeatReservation object held at a specific row and column (could be null, if not booked).
- An applyBookings method takes a List of SeatReservations, this method needs to look through the reservations one by one and ensure that the designated row and col is available in the two dimensional array of sessionSeats (ie not previously booked), otherwise the booking for those seats won't be made and the method will return false. It also needs to ensure that a child reservation cannot be booked in an R rated movie and a child reservation can only be made for an M rated movie if accompanied by an adult. If these conditions are not met then the booking for those seats won't be made and the method will return false. Otherwise if the condition is met and the seats are available the method then needs to apply the bookings. It does this by assigning each of the reservations held in the parameter list to the sessionSeats array matching their row and column values.
- It also has a printSeats method which prints out the sessionSeats array with an underline if empty, E for elderly, C for child and A for adult.
- Example for a 5x3 seating arrangement in G rated movie :
|_||A||_||_||_|
|_||A||E||C||_|
|_||A||_||C||C|

Question 5) Simple Driver
Create a suitable main method inside MovieSession which creates an ArrayList of different movie sessions with different times and ratings. Use the java.util.Collections class to sort the movies in order (this will test out whether your compareTo is correct in question 4.
For each of the movies try applying some bookings both when the seats are free and if the seats are taken, also try combinations of trying to book child tickets to both R and M rated movies both with and without an adult.

Question 6) MovieBookingGUI
Create a front end GUI called MovieBookingGUI for booking movies. It should be a subclass of JPanel and hold many different GUI components. It also will be used to listen for JButton and JList events. It also has the following features:
- A main method which creates an ArrayList of MovieSessions and sorts them using the Collections class, it then passes this to the MovieBookingGUI constructor during instantiation. It then creates a JFrame and adds the MovieBookingGUI object instance to it.
- The GUI should have JRadioButtons for selecting child, adult or elderly bookings and a
JCheckBox for declaring whether the booking is complementary
- The GUI should have a JList with a DefaultListModel for holding MovieSession objects which were passed in to the constructor with the currently displayed MovieSession selected. The list needs to listen for events.
- It should hold an ArrayList field called currentReservation which highlights seats as they are being selected. This holds the corresponding SeatReservations temporarily when selecting seats. This should be cleared once booked (by passing it into the applyBookings method of the currently displayed MovieSession), and cleared if the booking was cancelled or if a different MovieSession is selected in the JList.
- It should display a 2 dimensional array of JButtons called seatingButtons which represent seats in the theatre displaying corresponding row and column values as text inside each button. When selecting seats they become highlighted (by changing their foreground colour. YELLOW for child, WHITE for elderly or BLUE for adult) and added to the currentReservation list depending on whether an adult, child or elderly is being booked.
- The two dimensional array of buttons should be enabled if the seat is available. If a seat is taken then it should be disabled and have its background colour set to YELLOW for child, WHITE for elderly or BLUE for adult to indicate which reservation type is sitting in that seat.
- HINT: may want a helper method which enables/disables seating buttons and sets their background colour depending on which subclass of SeatReservation has filled the seat. This should be called whenever the currently displayed movie is changed, the bookings have been completed or cancelled.
- It should contain another JButton which cancels the current booking session, a JButton to exit the GUI and a JButton which tries to book the currentReservation inside the currently selected MovieSession calling its applyBookings method.
- If the applyBooking returns a false display a dialog telling the user that there was a mistake in the booking process (as perhaps seat has been filled or trying to book a child in an adult movie). Otherwise if successful then display a dialog box showing the number of tickets

booked and the total cost of the tickets. The currentReservation list then needs to be cleared ready for the next customer to book tickets.
- Plan out the GUI and think what extra JPanels are needed, what components they will hold and how they should be laid out with an appropriate LayoutManager.
- Bonus marks given for a good job with layout, handing unexpected user inputs and fully working functionality.

Here is a screenshot with B1-B4 already booked with 2 adult and elderly and a child. The user has tried to book D0 and D1 as child tickets, but need an adult with M-rated movie: Second screen shot shows that it now works and has been successfully booked as children are now accompanied with an elderly adult. The 3rd screenshot reflects these changes with the updated seatingButtons.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create suitable subclasses of seatreservation called
Reference No:- TGS02382651

Now Priced at $20 (50% Discount)

Recommended (99%)

Rated (4.3/5)