CASE STUDY^465
catch(NumberFormatException except)
{
outFile.println("NumberFormatException in site "+ dataSetName);
}
catch(DataSetException except)
{
outFile.println(except.getMessage() + dataSetName);
}
}
public static voidmain(String[] args) throwsFileNotFoundException,
IOException
{
String dataSetName; // Name of reporting station
BufferedReader inFile; // Data file
PrintWriter outFile; // Output file
inFile = newBufferedReader(newFileReader("rainData.dat"));
outFile = newPrintWriter(newFileWriter("outfile.dat"));
dataSetName = inFile.readLine(); // Get name of reporting station
do
{
processOneSite(inFile, outFile, dataSetName);
dataSetName = inFile.readLine(); // Get name of reporting station
} while(!dataSetName.equals("Quit"));
inFile.close();
outFile.close();
}
}
Testing:We should test two separate aspects of the Rainfallapplication. First, we
should verify that the application works correctly given valid input data. Supplying ar-
bitrary rainfall amounts of zero or greater, we must confirm that the application
correctly adds up the values and divides by 12 to produce the average. Also, we should
verify that the application behaves correctly when it reaches the sentinel value “Quit”.
Second, we should test the data validation code. We should include negative
numbers in the file to ensure that such data sets are not processed. Similarly, we need
to include some values that are improperly formed floating-point values. Here’s a sam-
ple input file that accomplishes the necessary testing: