How to call a method in another class using the arraylist index in java?

Posted by Puchatek on Stack Overflow See other posts from Stack Overflow or by Puchatek
Published on 2011-01-04T17:28:46Z Indexed on 2011/01/04 17:54 UTC
Read the original article Hit count: 186

Filed under:

Currently I have two classes. A Classroom class and a School class.

public void addTeacherToClassRoom(Classroom myClassRoom, String TeacherName)

I would like my method addTeacherToClassRoom to use the Classroom Arraylist index number to setTeacherName

e.g. int 0 = maths int 1 = science

I would like to setTeacherName "Daniel" in int 1 science.

many, thanks

    public class Classroom
{
private String classRoomName;
private String teacherName;

public void setClassRoomName(String newClassRoomName)
{
    classRoomName = newClassRoomName;

}

public String returnClassRoomName()
{
    return classRoomName;
}

public void setTeacherName(String newTeacherName)
{
    teacherName = newTeacherName;

}

public String returnTeacherName()
{
    return teacherName;
}
}





import java.util.ArrayList;

public class School
{
private ArrayList<Classroom> classrooms;
private String classRoomName;
private String teacherName;

public School()
{
    classrooms =  new ArrayList<Classroom>();
}

public void addClassRoom(Classroom newClassRoom, String theClassRoomName)
{
    classrooms.add(newClassRoom);
    classRoomName = theClassRoomName;
}

public void addTeacherToClassRoom(Classroom myClassRoom, String TeacherName)
{
    myClassRoom.setTeacherName(TeacherName);
}

}

© Stack Overflow or respective owner

Related posts about java