currently my program only reads in the one first name and last name with 5 grades and computes the average from the first line of my input file.
eg.
Albert Lake 54 23 54 32 12 average test score 35
im trying to edit this code so that the file reads in multiple first and last names each having 5 grades and does the average just like its doing. im sure its possible to read in multple names on new lines in a text file without introducing more variables, im just not sure how to accomplish this.
example of input file...
Albert Lake 54 23 54 32 12
Paul Brown 32 43 65 87 34
sam jones 32 45 65 76 87
....
please give me some ideas on how i can do this.
Ty
double test1, test2, test3, test4, test5;
double average;
String firstName;
String lastName;
StringTokenizer tokenizer;
BufferedReader inFile = new
BufferedReader (new FileReader ("a:\\test.txt"));
PrintWriter outFile = new
PrintWriter(new FileWriter ("a:testavg.txt"));
DecimalFormat twoDecimal = new DecimalFormat ("0.00");
tokenizer =
new StringTokenizer (inFile.readLine());
firstName = tokenizer.nextToken();
lastName = tokenizer.nextToken();
outFile.println ("Student Name: " + firstName + " " + lastName);
test1 = Double.parseDouble(tokenizer.nextToken());
test2 = Double.parseDouble(tokenizer.nextToken());
test3 = Double.parseDouble(tokenizer.nextToken());
test4 = Double.parseDouble(tokenizer.nextToken());
test5 = Double.parseDouble(tokenizer.nextToken());
outFile.println("Test scores: "
+ twoDecimal.format (test1) + " "
+ twoDecimal.format (test2) + " "
+ twoDecimal.format (test3) + " "
+ twoDecimal.format (test4) + " "
+ twoDecimal.format (test5));
average = (test1 + test2 + test3 + test4 + test5) /5.0;
outFile.println ("Average test score: "
+ twoDecimal.format(average));
outFile.close();
}
}