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

/*****************************Classroom.java**************************/


public class Classroom {

   /*
   * This is the composition because each class room must have class name , students, and teachers
   */
   private String className;
   private Student student1;
   private Student student2;
   private Student student3;
   private Student student4;
   private Teacher teacher1;
   private Teacher teacher2;

   /*
   * Creating class room
   */
   public Classroom(String className, Student student1, Student student2, Student student3, Student student4,
           Teacher teacher1, Teacher teacher2) {
       this.className = className;
       this.student1 = student1;
       this.student2 = student2;
       this.student3 = student3;
       this.student4 = student4;
       this.teacher1 = teacher1;
       this.teacher2 = teacher2;
   }

   public String getClassName() {
       return className;
   }

   public Student getStudent1() {
       return student1;
   }

   public Student getStudent2() {
       return student2;
   }

   public Student getStudent3() {
       return student3;
   }

   public Student getStudent4() {
       return student4;
   }

   public Teacher getTeacher1() {
       return teacher1;
   }

   public Teacher getTeacher2() {
       return teacher2;
   }

   public void arrangeClassRoom() {

       System.out.println("Arranging class room");
   }

   public void takeAttendance() {

       System.out.println("Attendance Taken");
   }

   //print class room
   @Override
   public String toString() {
       return "Class Room: " + className + "\nStudents: " + student1.toString() + "" + "\n" + student2.toString()
               + "\n" + student3.toString() + "\n" + student4.toString() + "\nTeachers: " + teacher1.toString() + "\n"
               + teacher2.toString();
   }

}

/**********************************Student.java****************************/


public class Student {

   private String name;
   private String major;

   public Student(String name, String major) {

       this.name = name;
       this.major = major;
   }

   public String getName() {
       return name;
   }

   public String getMajor() {
       return major;
   }

   public void read() {

       System.out.println("Reading Book");
   }

   @Override
   public String toString() {
       return "Name: " + name + "\nMajor: " + major + "\n";
   }

}

/************************************Teacher.java**************************/


public class Teacher {

   private String name;
   private String spec;

   public Teacher(String name, String spec) {

       this.name = name;
       this.spec = spec;
   }

   public String getName() {
       return name;
   }

   public String getSpec() {
       return spec;
   }

   public void teach() {

       System.out.println("Teaching");
   }

   @Override
   public String toString() {
       return "Name: " + name + "\nSpecification: " + spec + "\n";
   }

}
/**********************************TestClassroom.java**************************/


public class TestClassroom {

   public static void main(String[] args) {

       //creating classroom using composition
       Classroom c1 = new Classroom("Java class", new Student("JKS", "CS"), new Student("Virat", "ECE"),
               new Student("MS", "ELE"), new Student("Vijay", "CS"), new Teacher("Raj", "CS"),
               new Teacher("Ajay", "ECE"));
      
       System.out.println(c1.toString());
   }
}
/*********************output***********************/

Class Room: Java class
Students: Name: JKS
Major: CS

Name: Virat
Major: ECE

Name: MS
Major: ELE

Name: Vijay
Major: CS

Teachers: Name: Raj
Specification: CS

Name: Ajay
Specification: ECE

Please let me know if you have any doubt or modify the answer, 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.
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.
Research and explain in your words what is known as Object Oriented Programming. Then, identify two...
Research and explain in your words what is known as Object Oriented Programming. Then, identify two advantages of OOP for application development. In peer replies, choose from one of the following and define the concept as part of your response. Abstraction. Encapsulation. Inheritance. Polymorphism.
1. In Object Oriented Programming The private object fields can be directly manipulated by outside entities....
1. In Object Oriented Programming The private object fields can be directly manipulated by outside entities. Group of answer choices A. True B. False 2. __________ programming is centered on the procedures or actions that take place in a program. Group of answer choices A. Class B. Object-oriented C. Menu-driven D. Procedural/ Structural 3. __________ programming encapsulates data and functions in an object. Group of answer choices A. Object-oriented B. Class C. Menu-driven D. Procedural 4. The data in an...
What are the object oriented concepts and which all object oriented concepts are used in the...
What are the object oriented concepts and which all object oriented concepts are used in the given program? Consider the following code and explain how each of the object oriented concepts are applied in the given program. (CO1) class Vehicle { string brand; public: void honk(); void honk(int); }; void Vehicle::honk() { cout << "Tuut, tuut! \n" ; } void Vehicle::honk(int x) { for(int i=0;i<x;i++) cout << "Tuut, tuut! \n" ; } int main() { Vehicle V1; V1.honk(); V1.honk(3); }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT