首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
解析C/C++编程|讲解数据库SQL|辅导Python程序|辅导Web开发
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
+ 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.
<
>
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
+ 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
) : 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
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.
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
辅导 comm2000 creating socia...
2026-01-08
讲解 isen1000 – introductio...
2026-01-08
讲解 cme213 radix sort讲解 c...
2026-01-08
辅导 csc370 database讲解 迭代
2026-01-08
讲解 ca2401 a list of colleg...
2026-01-08
讲解 nfe2140 midi scale play...
2026-01-08
讲解 ca2401 the universal li...
2026-01-08
辅导 engg7302 advanced compu...
2026-01-08
辅导 comp331/557 – class te...
2026-01-08
讲解 soft2412 comp9412 exam辅...
2026-01-08
讲解 scenario # 1 honesty讲解...
2026-01-08
讲解 002499 accounting infor...
2026-01-08
讲解 comp9313 2021t3 project...
2026-01-08
讲解 stat1201 analysis of sc...
2026-01-08
辅导 stat5611: statistical m...
2026-01-08
辅导 mth2010-mth2015 - multi...
2026-01-08
辅导 eeet2387 switched mode ...
2026-01-08
讲解 an online payment servi...
2026-01-08
讲解 textfilter辅导 r语言
2026-01-08
讲解 rutgers ece 434 linux o...
2026-01-08
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!