Hey guys. I need help with a program I'm trying to write. I need to read scores from an ASCII file and display them. I also need to display an error message for any score that falls outside of the range of 0 to 100. And after doing that, I need to display an average of all of the VALID scores (scores from 0 to 100).
Here's my code so far:
import java.util.Scanner;
import java.io.*;
public class ReadAndAverageScores {
public static void main (String[] args)throws FileNotFoundException {
System.out.println("This program reads text from a file named 'TestScores.dat'.");
File anyFile = new File("TestScores.dat");
Scanner inputStream = new Scanner(anyFile);
System.out.println("-Contents of file "+anyFile+"-");
int lineNum=1;
while (inputStream.hasNextInt()){
System.out.println("Line "+lineNum+": "+inputStream.nextInt());
lineNum++;
}
}
}
I know how to read the scores, just not display the error message for the scores out side of the range and average the ones inside of the range.
Any help would be greatly appreciated!