In: Computer Science
Use composition relationship. What is composition? You will find out what composition in object oriented programming.
Based on the bedroom package below please create your own classroom package.
After completing entire package, you will write about your package specification in Readme.txt and also explain how you apply composition to your project.
package Bedroom;
public class Bedroom {
private String name;
private Wall wall1;
private Wall wall2;
private Wall wall3;
private Wall wall4;
private Ceiling ceiling;
private Bed bed;
private Lamp lamp;
public Bedroom(String name, Wall wall1, Wall wall2, Wall wall3,
Wall wall4, Ceiling ceiling, Bed bed, Lamp lamp){
this.name = name;
this.wall1 = wall1;
this.wall2 = wall2;
this.wall3 = wall3;
this.wall4 = wall4;
this.ceiling = ceiling;
this.bed = bed;
this.lamp = lamp;
}
public Lamp getLamp(){
return this.lamp; //return lamp
}
public void makeBed(){
System.out.println("Bedroom --> I am making my bed. ");
bed.make();
make();
}
public void make(){
straightenSheet();
fluffPillow();
}
public void straightenSheet(){
System.out.println("Straighten Sheet");
}
public void fluffPillow(){
System.out.println("Fluff pillow");
}
}
package classroom;
public class Classroom {
// Composition means keeping the things directly inside the
class.. So that the reference type keep existing
// even when the enclosed class gets destroyed.
private String className;
private Student students[];
private Teacher teacher;
private Whiteboard board;
private Projector projector;
public Classroom(String className){
this.className =
className;
this.students = new
Student[100];
this.teacher = new
Teacher("Deafult teacher");
this.board = new
Whiteboard();
this.projector =
new Projector();
}
public Lamp getProjector(){
return
this.projector;
}
public Lamp getTeacher(){
return
this.teacher;
}
public Lamp getWhiteboard(){
return
this.board;
}
public void make(){
System.out.println("Classroom
--> Switching lights");
System.out.println("Classroom
--> Setting up room");
setupProjector();
}
public void setupProjector() {
System.out.println("Setting
up projector");
}
}
**************************************************
I have tried to answer your question to best of my efforts.
However, if you still face any issues in the answer, please let me
know via the comment section. Your feedback will imporve as well as
encourage me to keep up the good work.
If i was able to help you, then please provide me an
upvote(thumbs up). Thanks!