Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 IntervalT start, T end this.start start; this.end end; public boolean containsT point return point.compareTostart && point.compareToend; public boolean subintervalInterval other return other.start.compareTostart && other.end.compareToend; public boolean overlapsInterval other return start.compareTootherend && end.compareTootherstart; public class Time implements Comparable private final int hours; private final int minutes; private final String meridian; public Timeint hours, int minutes, String meridian throws InvalidTime if hours hours minutes minutes meridian.equalsAM && meridian.equalsPM throw new InvalidTimeInvalid time input"; this.hours hours; this.minutes minutes; this.meridian meridian; public TimeString timeStr throws InvalidTime try String parts timeStr.split:; if partslength throw new InvalidTimeInvalid time format"; int hours Integer.parseIntparts; int minutes; String meridian; if partscontainsAM meridian AM; minutes Integer.parseIntpartsreplaceAMtrim; else if partscontainsPM meridian PM; minutes Integer.parseIntpartsreplacePMtrim; else throw new InvalidTimeInvalid meridian AMPM; if hours hours minutes minutes throw new InvalidTimeInvalid time range"; this.hours hours; this.minutes minutes; this.meridian meridian; catch NumberFormatException ArrayIndexOutOfBoundsException e throw new InvalidTimeInvalid time format"; @Override public int compareToTime other int thisTime this.hours this.minutes; int otherTime other.hours other.minutes; return Integer.comparethisTime otherTime; @Override public String toString return String.formatd:d s this.hours, this.minutes, this.meridian; public class InvalidTime extends Exception public InvalidTimeString message supermessage; import javax.swing.; import java.awt.; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Project public static void mainString args SwingUtilities.invokeLater createAndShowGUI; private static void createAndShowGUI JFrame frame new JFrameTime Interval Checker"; frame.setDefaultCloseOperationJFrameEXITONCLOSE; JButton compareButton new JButtonCompare Intervals"; JButton checkTimeButton new JButtonCheck Time"; Implement action listeners for the buttons compareButton.addActionListenernew ActionListener @Override public void actionPerformedActionEvent e JOptionPane.showMessageDialogframe "Compare Intervals button clicked."; Add your logic here for comparing intervals ; checkTimeButton.addActionListenernew ActionListener @Override public void actionPerformedActionEvent e JOptionPane.showMessageDialogframe "Check Time button clicked."; Add your logic here for checking time ; JPanel panel new JPanelnew GridLayout; Add buttons to the panel panel.addnew JLabel; panel.addnew JLabel; panel.addcompareButton; panel.addcheckTimeButton; frame.getContentPaneaddBorderLayoutCENTER, panel; frame.setSize; frame.setVisibletrue;
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 IntervalT start, T end
this.start start;
this.end end;
public boolean containsT point
return point.compareTostart && point.compareToend;
public boolean subintervalInterval other
return other.start.compareTostart && other.end.compareToend;
public boolean overlapsInterval other
return start.compareTootherend && end.compareTootherstart;
public class Time implements Comparable
private final int hours;
private final int minutes;
private final String meridian;
public Timeint hours, int minutes, String meridian throws InvalidTime
if hours hours minutes minutes meridian.equalsAM && meridian.equalsPM
throw new InvalidTimeInvalid time input";
this.hours hours;
this.minutes minutes;
this.meridian meridian;
public TimeString timeStr throws InvalidTime
try
String parts timeStr.split:;
if partslength
throw new InvalidTimeInvalid time format";
int hours Integer.parseIntparts;
int minutes;
String meridian;
if partscontainsAM
meridian AM;
minutes Integer.parseIntpartsreplaceAMtrim;
else if partscontainsPM
meridian PM;
minutes Integer.parseIntpartsreplacePMtrim;
else
throw new InvalidTimeInvalid meridian AMPM;
if hours hours minutes minutes
throw new InvalidTimeInvalid time range";
this.hours hours;
this.minutes minutes;
this.meridian meridian;
catch NumberFormatException ArrayIndexOutOfBoundsException e
throw new InvalidTimeInvalid time format";
@Override
public int compareToTime other
int thisTime this.hours this.minutes;
int otherTime other.hours other.minutes;
return Integer.comparethisTime otherTime;
@Override
public String toString
return String.formatd:d s this.hours, this.minutes, this.meridian;
public class InvalidTime extends Exception
public InvalidTimeString message
supermessage;
import javax.swing.;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Project
public static void mainString args
SwingUtilities.invokeLater createAndShowGUI;
private static void createAndShowGUI
JFrame frame new JFrameTime Interval Checker";
frame.setDefaultCloseOperationJFrameEXITONCLOSE;
JButton compareButton new JButtonCompare Intervals";
JButton checkTimeButton new JButtonCheck Time";
Implement action listeners for the buttons
compareButton.addActionListenernew ActionListener
@Override
public void actionPerformedActionEvent e
JOptionPane.showMessageDialogframe "Compare Intervals button clicked.";
Add your logic here for comparing intervals
;
checkTimeButton.addActionListenernew ActionListener
@Override
public void actionPerformedActionEvent e
JOptionPane.showMessageDialogframe "Check Time button clicked.";
Add your logic here for checking time
;
JPanel panel new JPanelnew GridLayout;
Add buttons to the panel
panel.addnew JLabel;
panel.addnew JLabel;
panel.addcompareButton;
panel.addcheckTimeButton;
frame.getContentPaneaddBorderLayoutCENTER, panel;
frame.setSize;
frame.setVisibletrue;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started