Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Question Hello. I am a new student of java class. I finished the question 1

ID: 3747679 • Letter: J

Question

Java Question

Hello. I am a new student of java class. I finished the question 1,2, and 3 but I struggle below question 4.

I should follow the given UML in second page.

Could anyone please help me?

Thank you so much.

Below codes are my Time and SeatReservation class.

public class Time implements Comparable<Time>{

private int hours;
private int mins;
private int secs;

public Time() {
hours = 0;
mins = 0;
secs = 0;
}

public Time(int hours) {
this();
this.hours = Math.max(0,Math.min(hours, 23));
  
}

public Time(int hours, int mins) {
this();
this.hours = Math.max(0,Math.min(hours, 23));
this.mins = Math.max(0,Math.min(mins, 59));
}

public Time(int hours, int mins, int secs) {
this();
this.hours = Math.max(0,Math.min(hours, 23));
this.mins = Math.max(0,Math.min(mins, 59));
this.secs = Math.max(0,Math.min(secs, 59));
}

public int getHours() {
return hours;
}

public void setHours(int hours) {
if(hours >= 0 && hours <= 23) {
this.hours = hours;
}
  
}

public int getMinutes() {
return mins;
}

public void setMinutes(int mins) {
if(mins >= 0 && mins <= 59) {
this.mins = mins;
}
  
}

public int getSeconds() {
return secs;
}

public void setSeconds(int secs) {
if(secs >= 0 && secs <= 59) {
this.secs = secs;
}
  
}

@Override
public boolean equals(Object otherTime) {
if (this == otherTime)
return true;
if (otherTime == null || getClass() != otherTime.getClass())
return false;
Time time = (Time) otherTime;
return hours == time.hours &&
mins == time.mins &&
secs == time.secs;
}

@Override
public String toString() {
return String.format("%02d:%02d:%02d", hours, mins, secs);
}

@Override
public int compareTo(Time time) {
int cmp = Integer.compare(hours, time.hours);
if(cmp == 0) {
cmp = Integer.compare(mins, time.mins);
if(cmp == 0) {
return Integer.compare(secs, time.secs);
} else {
return cmp;
}
} else {
return cmp;
}
}
  


public static void main(String[] args)
{
Time t = new Time(33,99,-15);
Time t2 = new Time(12,45,34);
  
System.out.println(t);
  
}
  
}

abstract class SeatReservation
{
private char row;
private int col;
protected boolean complementary;
  
public SeatReservation(char row, int col)
{
this.row = row;
this.col = col;
}
  
public abstract float getTicketPrice();
  
public void setComplementary(boolean complementary)
{
this.complementary = complementary;
}
  
public char getRow()
{
return row;
}
  
public int getCol()
{
return col;
}
}

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, convertRowTolndex 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<E> {
  
private String moviName;
private char rating;
private Time SessionTime;
private SeatReservation[][] sessionSeats;
public static final int NUM_ROWS;
public static final int NUM_COLS;

public MovieSession(String movieName, char sessionTime, Time Time);
public static int convertRowToIndex(char rowLetter);
public static int convertIndexToRow(char rowIndex);
public char getRating();
public String getMovieName();
public Time SessionTime();
public SeatReservation(char row, int col);
public boolean isSeatAvailable(char row, int col);
public boolean applyBookings(List<SeatReservation> reservations);
public void printSeats();
public String toString();
public int compareTo(E e);
public static void main(String [] args);
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote