Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need to be answered correctly. You must: Comment and Format and Must make sure a

ID: 3706720 • Letter: N

Question

Need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be flagged for review. MUST BE IN JAVA FORMAT. IT IS A MUST. Please also check the output very carefully. Must not provide the answer on a page. Use the Java compiler. Please provide the code in such a way so that it can be copied and checked in the Java compiler.

[6 marks] Question 3 The School class tracks the number of students and available room it currently has. The School class is aggregated from the ClassRoom class (which has the total number of rooms in the school) and a Student class (that has the total number of current students) The UML diagram for the three classes is given below. Study the diagram and answer the questions below School name: String rooms: ClassRoom std: Student + School (String, ClassRoom, Student): + getName () : String + getRooms () ClassRoom + getStd (): Student + setName (String): void + setRooms (ClassRoom) void + setStd (Student) void + stdPerR +toStrin Strin ClassRoom Student totalRooms: int -totalStudents: int + Student (int) +getTotalStudents (): int +ClassRoom (int): +getTotalRooms ): int + setTotalRooms( int) void + toStrin setTotalStudents ( int ): void Strin Strin + toStrin Write the constructor for School. You can assume that all the get/set methods in all the classes have been implemented. It should have a shallow copy of the ClassRoom and a deep copy of the Student i)

Explanation / Answer

package chegg;

public class School {

String name;

ClassRoom rooms;

Student std;

public School(String name, ClassRoom rooms, Student std){

this.name = name;

this.rooms = rooms;

this.std = std;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public ClassRoom getRooms() {

return rooms;

}

public void setRooms(ClassRoom rooms) {

this.rooms = rooms;

}

public Student getStd() {

return std;

}

public void setStd(Student std) {

this.std = std;

}

public int stdPerRoom(){

return std.totalStudents/rooms.totalRooms;

}

@Override

public String toString(){

return "Name = "+name+" "+rooms+" "+std;

}

}

class ClassRoom{

int totalRooms;

public ClassRoom(int totalRooms){

this.totalRooms = totalRooms;

}

public int getTotalRooms(){

return totalRooms;

}

public void setTotalRooms(int totalRooms){

this.totalRooms = totalRooms;

}

@Override

public String toString(){

return "Total Rooms = "+totalRooms;

}

}

class Student{

int totalStudents;

public Student(int totalStudents){

this.totalStudents = totalStudents;

}

public int getTotalStudents(){

return totalStudents;

}

public void steTotalStudents(int totalStudents){

this.totalStudents = totalStudents;

}

@Override

public String toString(){

return "Total Students = "+totalStudents;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote