I'm having trouble with a Java program. It involves a grade book in which I have created a public class named Student.
I have a user enter four grades for each student they want to enter. These grades are saved as doubles in an ArrayList in the Student class. I then have an ArrayList of Students.
Too get user input, I use an JOptionPane in a for loop programmed to iterate 4 times. All these values are added to a
temporay ArrayList of grades, then send that data to a new Student constructor, initializing the temporary grade book to the Student's variable. Then I clear(); the temporary grade book, fresh for a new Student.
However my program takes the last temporary grade book data, and applies them all to different Student's even though other data entered stays the same. Like a String for their name.
I don't have the code tonight, but I can get it posted tomorrow.
Thanks.
Edit: Changed title. ~VEdit: Here's the Code
CODE
ArrayList<Student> students = new ArrayList();
ArrayList<Double> grades = new ArrayList();
String input = JOptionPane.showInputDialog("How many students are you entering:");
int total = Integer.valueOf(input);
for(int a = 1; a <= total; a++)
{
grades.clear();
input = JOptionPane.showInputDialog("Student #" + a + " Name:");
String name = input;
input = JOptionPane.showInputDialog("Student #" + a + " ID:");
String ID = input;
for(int b = 1; b <= 4; b++)
{
input = JOptionPane.showInputDialog("Test Grade #" + b + ":");
double num = Double.valueOf(input);
grades.add(num);
}
students.add(new Student(name, ID, grades));
}
This post has been edited by Rhyotion: 17 May, 2007 - 07:21 AM