Java Interval & Time GUI Homework Answers
Your question:
This is a javafx…
The fourth programming project involves writing a program
to test the relationships between time intervals. The program should
contain four classes. The first class should be a generic class Interval
defined for any type that implements the comparable interface. Objects
of this type have a start and end of the generic type parameter that
defines the start and end of the interval. The class should be
immutable, so it should have no setter methods. At a minimum, it should
contain the following public methods: - A constructor that accepts the
start and end of an interval and constructs an Interval object - A
method within that is supplied an object of the generic type parameter
and returns whether that object is inside the interval, including the
endpoints - A method subinterval that is passed an interval as a
parameter and returns whether the interval parameter is a subinterval,
completely within, the interval on which the method is invoked - A
method overlaps that is passed an interval as a parameter and returns
whether the interval parameter overlaps the interval on which the method
is invoked The second class Time should contain two integer instance
variables that represent the hours and minutes and one additional
variable for the meridian, AM or PM. The class should implement the
Comparable interface and should be immutable, so it should have no
setter methods. At a minimum, it should contain the following public
methods: - A constructor that accepts the hours and minutes as integers
and the meridian as a string and constructs a Time object - A
constructor that accepts a string representation of a time in the format
HH:MM AM and constructs a Time object - A method compareTo that compares
two times and returns what is required of all such methods that
implement the comparable interface - A method tostring that returns the
string representation of the time in the format HH:MM AM When either
constructor is called, several checks need to be made on the input. For
both constructors, a check is needed to ensure that the hours and
minutes are within range and that the meridian is AM or PM. For the
constructor that accepts the string representation, additional checks
are needed to ensure that the hours and minutes are numeric values.
Should any check fail, an exception Invalidtime should be thrown that
includes the reason. The third class is the exception class Invaliatime
that implements a checked exception. It should have an instance variable
of type string that saves the message and the following method: - A
constructor that accepts the message as a string and constructs an
InvalidTime object The fourth class Project 4 should implement a GUI
interface that contains two buttons. The first button CompareIntervals
should compare the two intervals and output one of the following
messages depending upon how the intervals compare: - Interval 1 is a
sub-interval of interval 2 - Interval 2 is a sub-interval of interval 1
- The intervals overlap - The intervals are disjoint Shown below is an
example of the output when the CompareIntervals button is clicked: The
second button CheckTime should check whether the time is within the
intervals and output one of the following messages depending upon which
intervals it is within: - Both intervals contains the time HH:MM AM -
Only interval 1 contains the time HH:MM AM - Only interval 2 contains
the time HH:MM AM - Neither interval contains the time HH:MM AM Shown
below is an example of the output when the CheckTime button is
clicked:
Assignment Help Answers with Step-by-Step Explanation:
private final T start;
private final T end;
public boolean within(T value) {
return value.compareTo(start) >= 0 && value.compareTo(end) <= 0;
public boolean overlaps(Interval<T> other) {
return start.compareTo(other.end) <= 0 && end.compareTo(other.start) >= 0;
private final int hours;
private final int minutes;
this.meridian = meridian;
// Add input validation checks and throw InvalidTime exception if needed
}
@Override
@Override
public String toString() {
public class InvalidTime extends Exception {
public InvalidTime(String message) {
You can create a GUI using Java's Swing or JavaFX libraries to implement the `Project4` class. It should have two buttons ("CompareIntervals" and "CheckTime") and appropriate event handlers to perform the required comparisons and display the output messages.
Here's a simplified example of how you might structure your GUI class:
public static void main(String[] args) {
JFrame frame = new JFrame("Interval and Time Checker");
JButton compareButton = new JButton("CompareIntervals");
JButton checkButton = new JButton("CheckTime");
}
});
}
});
}


