Question: 2 . ( 2 5 min _ 3 0 points ) Given the following class definitions, draw the memory layout at the end of the

2.(25 min_30 points) Given the following class definitions, draw the memory layout at the end of the main method. You do not need to give concrete memory addresses. Draw the layout in the style we use in the class, with boxes and arrows.
public class University {
public String name;
public ArrayList departments;
public University(String name){
this.name= name;
this.departments = new ArrayList();
}
public void addDepartment(Department d){
departments.add(d);
d.setUniversity(this);
}
public String toString (){
String s="University "+ name +" has the following departments and corresponding students: ";
for (int i=0; i ";
s+=departments.get(i).printStudents();
}
return s;
}
} public class Department {
public String name;
public University Uni;
public ArrayList students;
public Department(String name, University Uni){
this.name=name;
this.Uni= Uni;
Uni.addDepartment(this);
students= new ArrayList();
}
public void setUniversity(University Uni){
this.Uni= Uni;
}
public void addStudent(Student s){
students.add(s);
}
public void removeStudent(Student s){
students.remove(s);
}
public String printStudents(){
String s="";
for (int i=0; i< students.size();i++)
s+=students.get(i).name +"";
return s;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!