Question

In: Computer Science

Use composition relationship. What is composition? You will find out what composition in object oriented programming....

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");
}

}

Solutions

Expert Solution

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!


Related Solutions

Use composition relationship. What is composition? You will find out what composition in object oriented programming....
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...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain. -What is a class diagram? How is it used in object-oriented programming? -What is an attribute in OOP? What is a data member? -What is a method in OOP? What is a member function? -What is the difference between private members and public members of a...
Throughout this course, you will be learning about object-oriented programming and demonstrating what you learn by...
Throughout this course, you will be learning about object-oriented programming and demonstrating what you learn by writing some programs in Java. The first step will be to install and integrated development environment (IDE) that will be where you will write and compile your programs. You will also write your first program using Java to show that you have correctly installed the IDE. The project instructions and deliverables are as follows: Download and install Java JDK and NetBeans IDE using the...
Why is it more feasible to use Objects and object oriented programming as compared to using...
Why is it more feasible to use Objects and object oriented programming as compared to using method based programs? What are the disadvantages of using only methods in your programs.
Take the Least Preferred Coworker Scale by Fiedler and find out if you are a relationship-oriented...
Take the Least Preferred Coworker Scale by Fiedler and find out if you are a relationship-oriented or task- oriented leader. Note your scores and comment on your opinion about the validity of this test as well as possible leanings in your leadership development.
This week, you will create and implement an object-oriented programming design for your project. You will...
This week, you will create and implement an object-oriented programming design for your project. You will learn to identify and describe the classes, their attributes and operations, as well as the relations between the classes. Create class diagrams using Visual Studio. Review the How to: Add class diagrams to projects (Links to an external site.) page from Microsoft’s website; it will tell you how to install it. Submit a screen shot from Visual Studio with your explanation into a Word...
In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will...
In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will use the concept of object aggregation (i.e., has-a relationship between objects). You will implement a Java application, called MovieApplication that could be used in the movie industry. You are asked to implement three classes: Movie, Distributor, and MovieDriver. Each of these classes is described below. The Movie class represents a movie and has the following attributes: name (of type String), directorsName (of type String),...
Explain what classes and objects are in object - oriented programming. Give an example of each...
Explain what classes and objects are in object - oriented programming. Give an example of each and explain how they work together in a computer program.
Briefly explain the terms used in object-oriented programming with examples.
Briefly explain the terms used in object-oriented programming with examples.
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create...
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create multi-threaded programs. Part I Create a class called Animal that implements the Runnable interface. In the main method create 2 instances of the Animal class, one called rabbit and one called turtle. Make them "user" threads, as opposed to daemon threads. Some detail about the Animal class. It has instance variables, name, position, speed, and restMax. It has a static boolean winner. It starts...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT