Hi again everyone. I am trying to change around this program I wrote to meet some new requirements, but getting stuck on how to do it.
*Write a program that reads a file consisting of students' test scores in the range of 0-200. The students scores should be stored into an array. It should then determine the number of students having sores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, and 175-200.
The first line in the input file will contain the number of students in the class.*
This is what I have to do... the program I had original would read in all the scores in the text file and output them to the console just fine, but my original array was dealing with the ranges of scores. I now need to change that so the student scores are used for the array, and the first number in the file is to show how many students in the class. I was trying to just edit my old program thinking it would be simple but I cant seem to get it to compile or run after all sorts of different tweaks. Any help appreciated.
-thanks-
import java.util.Scanner;
import java.io.*;
public class Grades
{
public static void main(String[] args)
throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("scores.txt"));
int range1, range2, range3, range4, range5, range6, range7, range8;
int numstudents, sgrades;
int begin = 0;
int end;
int[] gradeArray = new int[sgrades];
for (int i = 0; i < gradeArray.length; i++)
gradeArray[i] = 0;
while (inFile.hasNext())
{
int score = inFile.nextInt();
int index = score / 25;
gradeArray[index]++;
}
for (int i = 0; i < gradeArray.length; i++)
{
if (i == gradeArray.length - 1)
{
end = begin + 25;
}
else
{
end = begin + 24;
}
System.out.println(begin + "-" + end + ": " + gradeArray[i]);
begin = end + 1;
}
inFile.close();
}
}