Accessing methods of objects stored in an ArrayList
Title basically says it all...
I've got a class and a class nested inside that one, the outer class has an ArrayList object that stores objects of the nested class, and the objects of the nested class have their own ArrayList objects, and need to access/retrieve members of the inner classes' ArrayList objects, but don't know how.
Now the code, then more clarification.
Okay. So each ClassList has an ArrayList of students, and each student has an ArrayList of grades.
private String name;
private ArrayList grades;
private double mean;
public Student(String n, int g1, int g2, int g3, int g4)
name = n;
grades = new ArrayList();
private ArrayList students;
private int studentCount;
private ArrayList testMean;
private int testCount;
private double classMean;
students = new ArrayList();
testMean = new ArrayList();
studentCount = 0;
testCount = 4;
Assorted blank method stubs that will be filled in with accessing and setting commands, once I figure out how to access the inner array values.
Also a method that reads a .txt file and populates the ClassList arrayList of students and the student ArrayList of grades with values.
I can access each student object in the classList ArrayList, but I can only retrieve its memory address. I do not know how to access any values of the student objects' ArrayLists (which are stored in the ClassList arrayList and must be accessed from there).
Final attempt at explaining the problem: How the heck would I retrieve all the grades of a given student knowing only its index in the ClassList ArrayList?
Any help would be much appreciated. Thanks in advance.
I fail to see the problem :(
In my code above you see this:
right ?, now if i want to say, add a grade to the students
gra list, instead of reading the name
So if the grade was a class: Grade you would do
list.add(new Integer(19)); // a new grade added to list
ArrayList list=st.getGrades(); // list of Grade object
Grade aGrade=(Grade)list.get(0); // fix grade at position 0
aGrade.setPassed(true); // ... like
I can't get it simpler than this, sorry,