I wanted to ask how do we write this program to calculate the average test score of a 5 student
·Input: file containing 5 student’s first name, last name, five test scores
·Output: file containing 5student’s first name, last name, five test scores, average of five test scores
I have try it but all i get is errors..
I'm using NetBeans IDE 7.1 program..
------------------------------------------------------------------------------------------------
EDIT: Let's bring the code up here, it's more readable here:
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Homework {
public static void main(String[] args)throws FileNotFoundException {
Scanner inFile = new Scanner(new FileReader("FiveTestScores.txt"));
PrintWriter outFile = new PrintWriter("FiveTestScoresAverage.out");
String firstname;
String lastname;
int test1, test2, test3, test4, test5;
double average;
firstname = inFile.next();
lastname = inFile.next();
test1= inFile.nextInt();
test2= inFile.nextInt();
test3= inFile.nextInt();
test4= inFile.nextInt();
test5= inFile.nextInt();
System.out.println("Student Name: " + firstname + " " + lastname);
System.out.printf("Test scores: %2d %2d %2d " + "%2d %2d ", test1, test2, test3, test4, test5);
average = (test1 + test2 + test3 + test4 + test5) /5.00;
System.out.printf("\nAverage of test scores:%5.2f" , average);
inFile.close();
outFile.close();
}
}
if i do this steps 5 times it become an error..I want to why is that..
and how I could do it for 5 student.....
also it says that i can't write inFile.nextInt(); a lot of times... Why is that??
What can I do??