Question: Need UML diagram, test cases and lessons learned for program below. import java.util. * ; public class Interval > { private final T start; private

Need UML diagram, test cases and lessons learned for program below.
import java.util.*;
public class Interval>{
private final T start;
private final T end;
public Interval(T start, T end){
this.start = start;
this.end = end;
}
public boolean contains(T point){
return point.compareTo(start)>=0 && point.compareTo(end)<=0;
}
public boolean subinterval(Interval other){
return other.start.compareTo(start)>=0 && other.end.compareTo(end)<=0;
}
public boolean overlaps(Interval other){
return start.compareTo(other.end)<=0 && end.compareTo(other.start)>=0;
}
}
public class Time implements Comparable {
private final int hours;
private final int minutes;
private final String meridian;
public Time(int hours, int minutes, String meridian) throws InvalidTime {
if (hours <1|| hours >12|| minutes <0|| minutes >59||(!meridian.equals("AM") && !meridian.equals("PM"))){
throw new InvalidTime("Invalid time input");
}
this.hours = hours;
this.minutes = minutes;
this.meridian = meridian;
}
public Time(String timeStr) throws InvalidTime {
try {
String[] parts = timeStr.split(":");
if (parts.length !=2){
throw new InvalidTime("Invalid time format");
}
int hours = Integer.parseInt(parts[0]);
int minutes;
String meridian;
if (parts[1].contains("AM")){
meridian ="AM";
minutes = Integer.parseInt(parts[1].replace("AM","").trim());
} else if (parts[1].contains("PM")){
meridian ="PM";
minutes = Integer.parseInt(parts[1].replace("PM","").trim());
} else {
throw new InvalidTime("Invalid meridian (AM/PM)");
}
if (hours <1|| hours >12|| minutes <0|| minutes >59){
throw new InvalidTime("Invalid time range");
}
this.hours = hours;
this.minutes = minutes;
this.meridian = meridian;
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e){
throw new InvalidTime("Invalid time format");
}
}
@Override
public int compareTo(Time other){
int thisTime = this.hours *60+ this.minutes;
int otherTime = other.hours *60+ other.minutes;
return Integer.compare(thisTime, otherTime);
}
@Override
public String toString(){
return String.format("%02d:%02d %s", this.hours, this.minutes, this.meridian);
}
}
public class InvalidTime extends Exception {
public InvalidTime(String message){
super(message);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Project4{
public static void main(String[] args){
SwingUtilities.invokeLater(()-> createAndShowGUI());
}
private static void createAndShowGUI(){
JFrame frame = new JFrame("Time Interval Checker");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton compareButton = new JButton("Compare Intervals");
JButton checkTimeButton = new JButton("Check Time");
// Implement action listeners for the buttons
compareButton.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(frame, "Compare Intervals button clicked.");
// Add your logic here for comparing intervals
}
});
checkTimeButton.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(frame, "Check Time button clicked.");
// Add your logic here for checking time
}
});
JPanel panel = new JPanel(new GridLayout(4,2));
// Add buttons to the panel
panel.add(new JLabel(""));
panel.add(new JLabel(""));
panel.add(compareButton);
panel.add(checkTimeButton);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.setSize(300,200);
frame.setVisible(true);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!