I need to read the last name and five grades for 10 students from a file and calculate the average of the grades and display that information in a file.
I am pretty sure I know how to tackle this, but I have no clue how to separate the name (String) from the grades (int) in order to average the grades. This is a rough outline as to how I plan to average the grades. It does not work if I leave the name in the inFile.
public static void main(String[] args) throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("c:\\InputFile.txt"));
int sum = 0;
int num;
String firstName, lastName;
while (inFile.hasNext())
{
num = inFile.nextInt();
sum = sum + num;
}
sum = sum / 5;
System.out.printf("Sum = %d%n", sum);
I have an idea that arrays would work better for this problem, but we have not covered those yet and I am not familiar with them at all.