Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions