null
input, then empty input, then incorrectly formatted input (too few or too many fields), then incorrect values within a field.Conclusion
The lab activities for today included two applications of exceptions. One is checking user input in multiple fields for correctness. Our solution involves cascading tests, first for
The other is checking internal state of an object for consistency. We saw several examples of "isOK" methods, which check that internal information for the objects is logically consistent. Some of these checks involve class invariant relations (e.g. in the
TicTacToe
and Date
classes), while others involve loop invariant relations (the number-guessing code, the "moving X's to precede O's" code, and insertion sort). We observed a pattern for loop invariants among array values:for (int k=0; k<values.length; k++){
// At this point, the invariant is valid for the subarray
// that contains elements 0, 1, ..., k-1 of values.
Process element k of values.
// At this point, the invariant is valid for the subarray
// that contains elements 0, 1, ..., k of values.
}
Homework Submission
Submit
InsertionSort.java
and InsertionSortTest.java
for homework as
hw6
.Homework Assignments
Read the following:
- HFJ: Chapters 7 and 8
- JRS: Exceptions, Abstract Classes, .equals(), Field Shadowing