Project4-Documentation
Project4-Documentation
A. Below is the UML class diagram for the classes Interval, Time, InvalidTime, and
Project4.. In this UML diagram, predefined classes are omitted.
B.
In approaching this project, I began by thoroughly analyzing the requirements and did my
implementation on the individual components. I started with the ‘Time’ class, which required
careful consideration of how to represent time accurately and meaningfully. The class needed to
handle both integer inputs for hours and minutes, as well as a string format (HH:MM AM/PM).
To ensure the integrity of the time representation, I implemented constructors that enforced valid
hour ranges (1-12), valid minute ranges (0-59), and the correct meridian (AM/PM). This
involved writing logic to throw an ‘InvalidTime’ exception for any invalid inputs, which was
crucial for maintaining the robustness of the class. Additionally, I implemented the ‘compareTo’
method to facilitate time comparisons, which was essential for the later functionality of the
Interval class. By creating unit tests for the Time class, I ensured that it was working correctly
before integrating it with the other components.
Next, I turned my attention to the Interval class, which needed to be generic to accommodate any
type that implements the Comparable interface. I focused on defining this class with methods to
assess the relationship between intervals, such as within, subinterval, and overlaps. The within
method checks if a specific time falls within the interval, including the endpoints, while
subinterval determines if one interval is entirely contained within another. The overlaps method
checks for any intersection between two intervals. To maintain immutability, I ensured that the
class had no setter methods and that all data members were final. I also created unit tests for
these methods to validate their behavior. This modular approach allowed me to confirm that each
class was functioning as intended before moving on to the graphical user interface.
For the GUI, I chose to use Java Swing due to its versatility and ease of use in building desktop
applications. I designed the layout using a grid layout to ensure that all components were
arranged logically and intuitively. The first row consisted of labels for "Start Time" and "End
Time," followed by rows for inputting time intervals for two separate intervals. I implemented
buttons for comparing intervals and checking specific times, ensuring that they spanned the full
width for better visibility and accessibility. Each button was linked to an ActionListener that
encapsulated the logic for its functionality. For instance, the "Compare Intervals" button checks
the relationships between the two intervals, while the "Check Time" button verifies if a specified
time falls within the given intervals. To facilitate testing and debugging, I created a detailed test
plan that outlined various test cases, including edge cases like overlapping intervals and invalid
time inputs. This comprehensive approach ultimately enhanced my understanding of software
design principles and improved my programming skills significantly.