So i have a problem that reads: Each line of the file consists of a student’s name followed by an unpredictable number of test
scores. The number of students is also unpredictable. The desired output is as shown where the
numbers there represent the average test score rounded to the nearest whole number.
Create a class called StudentAverages that will input the StudentScores.in text file and produce
the indicated output.
i attached the file that i have to read from.
My code so far is:
import java.io.*;
import java.util.*;
public class fdhg
{
public static void main(String args[]) throws IOException
{
Scanner sf = new Scanner(new File("Grades.txt"));
int maxIndx = -1;
String text[] = new String[1000];
while(sf.hasNext())
{
maxIndx++;
text[maxIndx]=sf.nextLine();
}
sf.close();
String answer="";
int sum=0;
double average=0;
int n=0;
String a="";
for(int j=0;j<=maxIndx; j++)
{
Scanner sc=new Scanner(text[j]);
sum=0;
String s="";
n=0;
while(sc.hasNext())
{
int i=sc.nextInt();
sum=sum+i;
n=n+1;
}
average=sum/n;
System.out.println(average);
}
}
}
So i know how to get the averages if there were just numbers in the file but there is a name at the beginning. How do i print out their name with out having any idea what the contents of the file are. thanks for any help you can offer.