Thanks! HelloWorld922
I think this is what my teacher is looking for:
new improve code:
import java.util.*; import java.io.*; public class average { public static double calculateAverage(double average, double test1, double test2, double test3, double test4, double test5){ average = (test1 + test2 + test3 + test4 + test5) / 5.0; return average;} public static char calculateGrade(double score){ char grade; if (score >= 90) grade = 'A'; else if (score >= 80) grade = 'B'; else if (score >= 70) grade = 'C'; else if (score >= 60) grade = 'D'; else grade = 'F'; return grade;} public static void main(String[] args) throws FileNotFoundException{ double test1, test2, test3, test4, test5, sAverage, classAverage; double average = 0; String student; char sAvgGrade; double sum = 0; double count = 0; Scanner inFile = new Scanner(new FileReader ("C:\\Class.txt")); PrintWriter outFile = new PrintWriter ("C:\\Class.out"); outFile.println("Student Test1 Test2 Test3 Test4 Test5 Average Grade"); while (inFile.hasNext()){ student = inFile.next(); test1 = inFile.nextDouble(); test2 = inFile.nextDouble(); test3 = inFile.nextDouble(); test4 = inFile.nextDouble(); test5 = inFile.nextDouble(); sAverage = calculateAverage(average, test1, test2, test3, test4, test5); sAvgGrade = calculateGrade(sAverage); outFile.printf("%-7s %5.0f %5.0f %5.0f %5.0f %5.0f %8.2f %3c %n", student, test1, test2, test3, test4, test5,sAverage, sAvgGrade); sum = sum + sAverage; count++;} outFile.println(""); outFile.println("Class Average = "+ sum/count); inFile.close(); outFile.close(); } } i cant test this out tho so i have no clue if its working or not. T_T