If someone has a second, could you please take a look at this. This is just a small part to a large program I have to write for school. Right now I'm just trying to get the arrays to load.
I can't get my two dimesinal array to work (the loadAssignments method at the bottom). It compiles ok, but then I get an error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at finalGradeReport.loadAssignments(finalGradeReport.java:68)
at finalGradeReport.main(finalGradeReport.java:31)
I researched that error, and I guess it means an illegal index is being accessed..but I'm not sure why.
The assignments files looks like this...
01 90 80 70 95 96 97 80 80 70 100
02 71 72 73 74 75 76 77 78 89 80
03 81 82 83 84 85 86 87 88 89 90
04 91 92 81 82 83 91 71 0 0 0
05 100 100 100 100 100 99 99 99 88 77
student numbers being in the first column.
I'm guessing it's something simple, but I really don't want to wait til my next class to figure it out.
public static void main(String[] args) //Main Program
{ //Start Main
String name="";
int totalStudents;
Keyboard kbd; //create keyboard
kbd = new Keyboard ();
InputFile students; //create file to read
students = new InputFile ("H:\\MaxSync\\School\\SLCC\\CIS 1030\\finalGradeReport\\students.txt");
InputFile assignments; //create file to read
assignments = new InputFile ("H:\\MaxSync\\School\\SLCC\\CIS 1030\\finalGradeReport\\assignments.txt");
OutputFile report; //creat new outputfile
report = new OutputFile ("H:\\MaxSync\\School\\SLCC\\CIS 1030\\finalGradeReport\\report.txt");
//header (report);
int [] numberArray;
numberArray = new int [5];
String [] nameArray;
nameArray = new String [5];
loadStudentInfo (students, numberArray, nameArray);
loadAssignments (assignments, numberArray);
}
public static void loadStudentInfo (InputFile students, int [] numberArray, String [] nameArray)
{
int x=0;
for (x = 0; !students.eof(); x++)
{
numberArray[x]=students.readInt ();
nameArray[x]=students.readLine ();
}
}
public static void loadAssignments (InputFile assignments, int [] numberArray)
{
int x;
int y;
int [] [] matrix;
matrix = new int [5] [10];
for (x = 0, y = 0; !assignments.eof(); x++)
{
numberArray[x]=assignments.readInt ();
matrix[x][y]=assignments.readInt ();
}
}
}