Hi i am a java student and i have trouble with this question, can anyone help me
ID: 3748344 • Letter: H
Question
Hi i am a java student and i have trouble with this question, can anyone help me.
Since question 4 is related to question 1 i will attach question 1 too.
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. ·Explanation / Answer
public class MovieSession implements Comparable<MovieSession> {
private String movieName;
private char rating;
private Time sessionTime;
private SeatReservation[][] sessionSeats;
public static int NUM_ROWS;
public static int NUM_COLS;
public MovieSession(String movieName, char rating, Time sessionTime) {
this.movieName = movieName;
this.rating = rating;
this.sessionTime = sessionTime;
}
if (time1.compareTo(time2) > 0) { // Like "time1 > time2"
}
@Override
public int compareTo(MovieSession currentMovieSession) {
if (this.sessionTime < currentMovieSession.sessionTime)
{
return -1;
}
else if (this.sessionTime > currentMovieSession.sessionTime)
{
return 1;
}
if(this.sessionTime == currentMovieSession.sessionTime)
{
return this.movieName > currentMovieSession.movieName ? 1 : -1;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.