Q:

How do I use a Java method to process an input file line-by-line from within a loop?

I am using Java to process a file by calling multiple methods for each line of input from within a loop. The problem is that methods only read the first line of input for every iteration of the loop. For example, this input:
Jones 90 90 90
Brown 80 80 80
Smith 70 70 70

Should result in output of:
Jones 90 A
Brown 80 B
Smith 70 C

But instead I end up with:
Jones 90 A
Brown 90 A
Smith 90 A

Is it possible to get the studentAverage and determineGrade methods in the code below to process the second and third lines of input as in the above example, or do I need to reconsider the entire loop/method structure?
import java.io.*;
import java.util.Scanner;

public class Lab07Part01
{
    public static void main(String[] args) throws IOException
    {
        File infile = new File("Grades.txt");
        Scanner myfile = new Scanner(infile);
        Scanner counter = new Scanner(infile);

        String studentName = "";
        int testQty = 0;
        int studentQty = -1;
        double studentAvg = 0.0;
        double classSum = 0.0;
        double classAvg = 0.0;
        char letterGrade = 'X';

        while(counter.hasNextLine()) {
            studentQty++;
            counter.nextLine();
        }

        testQty = myfile.nextInt();

        System.out.println("Name   Average   Letter Grade");
        for(int i = 0; i < studentQty; i++) {
            studentName = myfile.next();
            studentAvg = studentAverage(testQty);
            classAvg += studentAvg;
            letterGrade = determineGrade(studentAvg);
            System.out.println(studentName + " " + studentAvg + " " + letterGrade);
            myfile.nextLine();
        }

        classAvg = overallAverage(studentQty, classSum);

        System.out.println("The average test grade is: " + classAvg);

    }

    public static double studentAverage(int testQty) throws IOException
    {
        File infile = new File("Grades.txt");
        Scanner scanavg = new Scanner(infile);
        double studentSum = 0;

        scanavg.nextLine();
        scanavg.next();

        for(int i = 1; i <= testQty; i++) {
            studentSum += scanavg.nextDouble();
        }

        double studentAvg = studentSum / testQty;
        return studentAvg;
    }

    public static char determineGrade(double studentAvg) throws IOException
    {
        char letterGrade = 'X';

        if(studentAvg >= 90.0)
            letterGrade = 'A';
        else if(studentAvg >= 80.0)
            letterGrade = 'B';
        else if(studentAvg >= 70.0)
            letterGrade = 'C';
        else if(studentAvg >= 60.0)
            letterGrade = 'D';
        else if(studentAvg < 60.0)
            letterGrade = 'F';

        return letterGrade;
    }

    public static double overallAverage(int studentQty, double classSum) throws IOException
    {
        double classAvg = classSum / studentQty;
        return classSum;
    }
}

A:

I would use the scanner by reading in an entire line at a time.  Then, we can process that entire line in one logical step:
File infile = new File("Grades.txt");
Scanner myfile = new Scanner(infile);

while (myfile.hasNextLine()) {
    String line = myfile.nextLine();
    String[] parts = line.split("\\s+");
    double average = 0.0d;
    for (int i=1; i < parts.length; ++i) {
        average += Double.parseDouble(parts[i]);
    }
    average /= parts.length - 1;
    char letterGrade = determineGrade(average);

    System.out.println(parts[0] + " " + average + " " + letterGrade);
}

