Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The fourth programming project involves writing a program to test the relationships between time intervals. The program should contain four classes. The first class

The fourth programming project involves writing a program to test the relationships between time intervals. The fourth class Project 4 should implement a GUI interface that contains two buttons. The first button Time Interval Checker Time Interval 1 Time Interval 2 Time to Check Start Time 10:30 AM 11:05 AM Compare

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 compare To 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 InvalidTime 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: Time Interval Checker Time Interval 1 Time Interval 2 Time to Check The intervals overlap Start Time 10:30 AM 11:05 AM Compare Intervals Check Time End Time 12:30 PM 1:00 PM X 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: Time Interval Checker Time Interval 1 Time Interval 2 Time to Check Start Time 10:30 AM 11:05 AM Compare Intervals 12:50 PM Check Time Only interval 2 contains the time 12:50 PM End Time 12:30 PM 1:00 PM X

Step by Step Solution

3.34 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

class Interval def in... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

Students also viewed these Programming questions

Question

What is coal?

Answered: 1 week ago

Question

Explain the goal of behavior therapy.

Answered: 1 week ago

Question

Compare and contrast licensing and subcontracting.

Answered: 1 week ago

Question

How has technology had an impact on product design?

Answered: 1 week ago