CASE STUDY^463
The only abstract step left is to determine when the outer loop finishes. We could
read in a new site name and quit if there are no more data, or we could use a site name
of “Quit” to end the processing. Let’s use the latter technique here.
Assumptions:The file contains data for at least one site.
packagerainfall;
// Define an Exception class for signaling data set errors
public classDataSetException extendsException
{
publicDataSetException()
{
super();
}
publicDataSetException(String message)
{
super(message);
}
}
packagerainfall;
importjava.io.*;
public classRainfall
// ****
// Rainfall application
// This application accepts input of 12 monthly rainfall amounts from a recording
// site and computes the average monthly rainfall.
// This process is repeated for as many recording sites as the user wishes.
// ****
More Data
dataSetName is not "Quit"
Catch and Handle Exceptions
catchIOException
Write "I/O Exception with site " + data set name
End application
catchNumberFormatException
Write "NumberFormatException with site " + data set name
catchDataSetException
Write message + data set name