There are no Processing-specific sections in this chapter because Processing does not support exception handling and because it's difficult to unit test graphical applications.
This chapter revisits the Temperature class developed in Chapter 9 and extends it to support robust, correct behavior. Read this section to get ready for the chapter examples.
Try running the following code segment.
int a = null; System.out.println(a.length);
Explain what happens and why it happens. Pay particular attention to the concept of exceptions.
e.getMessage()) as shown in the text, Section 10.2.3.
Consider whether you would ever need to throw and exception in a default constructor.
How is throwing an exception, say in the
mutator for the temperature class, different and/or better than printing error messages and
exiting the program (as we did in Chapter 9’s version of the temperature example).
You don't need to compile and run this code in your IDE - you’ll see how to do that in the lab exercise; just write the test code here based on the examples you see in the text.
Consider the two assertion commands in the following code segment.
double x = 1.0, y = 1.0; assertEquals(x, y, 1e-3); assertTrue(x == y);
Do these two assertions test the same thing? Would they return the same value regardless of
the values of
Many programmers avoid writing unit tests because they take extra time. Can you imagine a circumstance in which they would be valuable?
Just read through this section, focusing on the potential value of usability testing and on the model-view distinction.
If possible, you’ll participate as a subject in a usability test this semester.
Enumerated types are useful, but they are less important to us now that the material in the other sections. Read through this chapter only if you have time and interest.
Just read through this one as well.