联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2018-09-19 02:20


Programming 2: Assignment 2 (50 marks maximum)

Due: Monday 1st October 2018

Please submit your code to Blackboard under the correct assignment folder by 11:59pm on the due

date. Place all Java source code (Classes with extension .java) into a folder with your name and student

id eg: Jack_Bloggs_1293849 and zip it up (Jack_Bloggs_1293849.zip).

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 (10 marks)

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.

Time

- hours : int

- mins : int

- secs : int

+Time()

+Time(hours:int)

+Time(hours:int,mins:int)

+Time(hours:int,mins:int,secs:int)

+setSeconds(secs:int):void

+setMinutes(mins:int):void

+setHours(hours:int):void

+getSeconds():int

+getMinutes():int

+getHours():int

+equals(otherTime: Object) : boolean

+toString() : String

Comparable<E>

+ compareTo(e : E) : int

Question 2) SeatReservation (5 marks)

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. (5 marks)

Question 3) SeatReservation subclasses (5 marks)

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 for that ticket is zero. (5 marks)

Question 4) MovieSession (15 marks)

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.

<<abstract>>

SeatReservation

- row : char

- col : int

# complementary : boolean

+SeatReservation(row:char, col:int)

+ getTicketPrice() : float

+setComplementary(complementary:boolean) :void

+getRow() : char

+getCol() : int

• 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|

Comparable<E>

+ compareTo(e : E) : int

MovieSession

- movieName : String

- rating : char

- sessionTime : Time

- sessionSeats : SeatReservation[][]

+ NUM_ROWS : int

+ NUM_COLS : int

+MovieSession(movieName:String, rating:char, sessionTime:Time)

+convertRowToIndex(char rowLetter) : int

+convertIndexToRow(int rowIndex) : char

+getRating() : char

+getMovieName() : String

+getSessionTime() : Time

+getSeat(row:char, col:int) : SeatReservation

+isSeatAvailable( row:char, col:int) : boolean

+applyBookings(reservations:List<SeatReservation>) : boolean

+printSeats() : void

+toString() : String

+main(args:String) : void

Question 5) Simple Driver (5 marks)

Create a suitable Driver class 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 one 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. This class simply tests some basic operations for the developed classes.

Question 6) MovieBookingGUI (10 marks + 5 bonus)

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<SeatReservation> 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.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp