How to call a method in another class using the arraylist index in java?
- by Puchatek
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);
}
}