Getting variable array to hold information. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Getting variable array to hold information.

nickleme06nickleme06 Posts: 1Member
I am trying to do an array with a variable length. This array also accepts user input. when I try to print out the array all I am getting is the last student entered. Any suggestions. Here is my code for my array.
int numberOfStudents = getStudentCount();

System.out.println();
studentArray = new Student [numberOfStudents];
for (int i = 0; i < numberOfStudents; i++)
{
studentArray[i] = new Student(lastName, firstName, score);
lastName = getString("Student " + i + " Last Name: ");
firstName = getString("Student " + i + " First Name: ");
score = getScore("Student " + i + " score: ");
System.out.println();
finalScore = Integer.toString(score);

}
Arrays.sort(studentArray);
System.out.println(lastName + ", " + firstName + ": " + score);
sum += score;
average = sum/numberOfStudents;
System.out.println("Class Average =" + average);
}
Sign In or Register to comment.