Currently writing a program that displays what's in a different file. What I need to do is process the data in the file so i can get three things. I need to count the number of records, and compute the mean age and GPA.
What's confusing me is how I would go about separating the file to do each thing individually.
Here's what I have so far.
/**
* @(#)Lab17.java
*
*
* @author
* @version 1.00 2008/3/17
*/
import java.io.*;
import java.text.DecimalFormat;
public class Lab17 {
public static void main(String args[]) throws IOException
{
DecimalFormat df = new DecimalFormat("00.000");
File f1 = new File("students17.dat");
File f2 = new File("passing.dat");
File f3 = new File("honors.dat");
f2.delete();
f3.delete();
if (f1.exists())
{
FileReader inFile = new FileReader(f1);
BufferedReader inStream = new BufferedReader(inFile);
String inString;
while((inString = inStream.readLine()) != null)
System.out.println(inString);
int rec = Integer.parseInt(inString);
int sum = 0;
sum += rec;
inStream.close();
System.out.println(sum);
}
else
{
System.out.println(f1.getName() + " does not exist");
}
System.out.println();
}
}
I get this error with the current adding I have going. I'm betting because it's trying to add letters in as well.
Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at Lab17.main(Lab17.java:30)