Hi
I have the following program I get an error sayin Exception in "Main" .
Can anybody tell me where am I wrong.
import java.io.*;
public class RainFall
{
// Declare dataFile for input
private static BufferedReader dataFile;
static double getInches(BufferedReader dataFile, int numberDays)
throws IOException
// Reads and returns the total inches of rain
{
double total = 0.0;
double inches;
int days = 1;
while (days <= numberDays)
{
inches = Double.valueOf(dataFile.readLine()).doubleValue();
total = total + inches;
days++;
}
return total;
}
public static void main(
String[] args) throws IOException
// Main is where execution starts. It opens the data file,
// reads the number of days of rain to be totaled, calls an
// auxiliary method to read and sum the rain fall, and prints
// the average rain fall on the screen
{
double totalRain;
int numDays;
double average;
// Instantiate and open the data file
dataFile = new BufferedReader(new FileReader("rainFile.in"));
// Input the number of days
numDays = Integer.valueOf(dataFile.readLine()).intValue();
totalRain = getInches(dataFile, numDays);
if (numDays == 0)
System.out.println("Average cannot be computed for 0 days.");
else
{
average = totalRain / numDays;
System.out.println("The average rainfall over " +
numDays + " days is " + average);
}
dataFile.close();
}
}