Seem to be having trouble. The trouble i'm having is the calculateAverage, and a bit of the public static main void area. I'll explain:
calculateAverage: What i'm suppose to do is read from the txt file. I tried doing the inFile.nextDouble part, but seem to be getting errors. i'm not sure if I have to input parameters like calculateGrade. Or somehow involve the scanner code. Or try using a loop method.
Therefore my objective on this part: read the five scores from input file.
calculateGrade: 100% fine with this, so skip.
main method: Line51: i'm suppose to set average to call of calculateAverage, as well as calculateGrade. would I have to do something like...
sAverage = calculateAverage();?
sGrade = calculateGrade(average);.
That's pretty much it. It's the average variable that seems to be my issue. It just needs a few tweaks on that part as well as the main method area, and then I should be set. Any help is appreciated. Just need a point to the right direction Here is my code:
import java.util.*;
import java.io.*;
public class Grades {
public static double calculateAverage()
{
average = ((Test1 + Test2 + Test3 + Test4 + Test5) / 5.0);
return average;
}
public static String calculateGrade(double average)
{
if (average >= 90)
return "A";
else if (average >= 80)
return "B";
else if (average >= 70)
return "C";
else if (average >= 60)
return "D";
else
return "F";
}
public static void main (String [] args) throws FileNotFoundException {
String grade = "";
int count = 0;
double sum = 0.0;
String Name;
String sAvgGrade = "";
double Test1, Test2, Test3, Test4, Test5, sAverage, classAverage;
System.out.println("Student Test1 Test2 Test3 Test4 Test5 Average Grade");
Scanner inFile = new Scanner(new FileReader ("Students.txt"));
while(inFile.hasNext())
{
Name = inFile.nextLine();
System.out.println(Name);
Test1 = inFile.nextDouble();
Test2 = inFile.nextDouble();
Test3 = inFile.nextDouble();
Test4 = inFile.nextDouble();
Test5 = inFile.nextDouble();
//Confused here;
System.out.printf("%2d %s\n", average, grade);
sum = sum + sAverage; //***Need to set sAverage***
count++;
System.out.println("");
System.out.println("Class Average = " + sum/count);
inFile.close();
}
}
}