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;
}
}
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);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.