I am writing a program to keep track a school's classes and students. I have School, Classroom, and Student objects. The school contains an ArrayList of classroom objects and each classroom contains an ArrayList of student objects.
I am trying to write a method in the School class to remove a student using a String name and String classroomName as a parameter.
This is what I have so far:
public void remove( String studentName, String classroomName) {
for(Classroom c : classes) {
if(c.className.equals(classroomName)){
//search for student and remove
for(Student s : students){
if(s.studentName.equals(studentName)){
s.remove(studentName);
}
}
}
}
I think this is not working because the ArrayList of Student objects is declared in the Classroom class.
Is there a way to search through an object ArrayList for an element using a non object parameter?