0% found this document useful (0 votes)
13 views3 pages

Project4-Documentation

The document outlines the UML class diagram and testing procedures for classes related to time intervals, including valid and invalid interval creation, methods for checking subintervals and overlaps, and GUI functionalities. It details the implementation of the Time and Interval classes, emphasizing the importance of input validation and immutability. Additionally, it describes the design of a Java Swing GUI for user interaction and the creation of a comprehensive test plan to ensure functionality and robustness.

Uploaded by

munabedan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Project4-Documentation

The document outlines the UML class diagram and testing procedures for classes related to time intervals, including valid and invalid interval creation, methods for checking subintervals and overlaps, and GUI functionalities. It details the implementation of the Time and Interval classes, emphasizing the importance of input validation and immutability. Additionally, it describes the design of a Java Swing GUI for user interaction and the creation of a comprehensive test plan to ensure functionality and robustness.

Uploaded by

munabedan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

2.

A. Below is the UML class diagram for the classes Interval, Time, InvalidTime, and
Project4.. In this UML diagram, predefined classes are omitted.

B.

Test Description Required Test Steps Expected Pass


Cas Result /Fail
e
TC1 Test valid 1. Create an Interval with valid start and Interval is
interval end times: created with the
creation - Time Interval 1: Time(10, 30, "AM") to correct start and
Time(12, 30, "PM") end times.
- Time Interval 2: Time(1, 00, "PM") to
Time(2, 00, "PM")
TC2 Test invalid 1. Attempt to create an Interval with start An
interval (start > time later than end time: IllegalArgument
end) - Start: Time(1,00, "PM") Exception is
- End: Time(12,0 0, "PM") thrown
indicating that
the start time
cannot be after
the end time.
TC3 Test within 1. Create an Interval: Returns true for
method - Time Interval: Time(10, 30, "AM") to times within and
Time(12, 30, "PM") on the
2. Check if Time(11, 00, "AM") is within endpoints; false
the interval. for Time(1, 0,
3. Test with: "PM").
- Time(10, 30, "AM") (on the start)
- Time(12, 30, "PM") (on the end)
TC4 Test 1. Create two Interval objects: Returns true if
subinterval - Interval 1: Time(10, 30, "AM") to Interval 2 is
method Time(12, 30, "PM") completely
- Interval 2: Time(11, 00, "AM") to within Interval
Time(11, 30, "AM") 1; false
2. Check if Interval 2 is a subinterval of otherwise.
Interval 1.
TC5 Test overlaps 1. Create two overlapping intervals: Returns true if
method - Interval 1: Time(10, 30, "AM") to the intervals
Time(12, 30, "PM") overlap; false
- Interval 2: Time(11, 00, "AM") to otherwise.
Time(1, 00, "PM")
2. Check if they overlap using the overlaps
method.
TC6 Test GUI for 1. Run the GUI application. Displays a
interval 2. Input two time intervals: message
comparison - Time Interval 1 Start: 10:30 AM indicating
- Time Interval 1 End: 12:30 PM whether the
- Time Interval 2 Start: 11:05 AM intervals
- Time Interval 2 End: 1:00 PM overlap, are
3. Click the "Compare Intervals" button. disjoint, or if
one is a
subinterval.
TC7 Test GUI for 1. Run the GUI application. Displays a
checking time 2. Input a time to check against the message
intervals: indicating which
- Time to Check: 12:50 PM intervals (if any)
3. Click the "Check Time" button. contain the
specified time
(e.g., "Only
interval 2
contains the
time 12:50
PM").
3. Discussion of Approach

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.

You might also like