(1) Assuming the grades are stored in the file "C:\Grades.txt".
=====================================
import java.io.FileInputStream;
public class GradeCalculator {
private String gradesFilename;
public GradeCalculator(String filename) {
gradesFilename = filename;
}
public void printAverages() {
try {
FileInputStream fis = new FileInputStream(gradesFilename);
byte[] bytes = new byte[1024];
fis.read(bytes);
String text = new String(bytes);
fis.close();
String[] lines = text.split("\n");
for(int i=0; i
String[] studentData = lines[i].split(" ");
String name = studentData[0];
int total = 0;
int count = 0;
for(int j=1; j
int grade = Integer.parseInt(studentData[j]);
total += grade;
count++;
}
int average = total/count;
System.out.println("Output = " + name + ", Average = " + average);
}
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main (String[] args) {
GradeCalculator calc = new GradeCalculator("C://Grades.txt");
calc.printAverages();
}
}
=====================================
(2) The output of the code will be:
=====================================
Output = Agnes, Average = 80
Output = Bufford, Average = 91
Output = Julie, Average = 96
Output = Alice, Average = 33
Output = Bobby, Average = 94
=====================================