1) Write a class called Room, which has three private instance variables: a) a double width,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1) Write a class called Room, which has three private instance variables: a) a double width, representing the width of the room in feet, b) a double length, representing the length of the room in feet, and c) an int floor, representing the building floor that the room is on. 2) Write a default constructor for the class Room that sets the width to 10, the length to 12.5, and the floor to 1. 3) Write get and set methods ("getters" and "setters") for the three instance variables. For the set methods for the width and length, only positive values should be set. If the input is 0 or a negative number, the variables should not be changed. 4) Write a constructor for the class Room that takes in two double parameters and an int, and sets length to the larger double, width to the smaller double, and floor to the int. Use the setters from part (b). 5) Override the default toString method for the class Room, so when called by an instance of Room created by the default constructor from part (a) would return the String: "Room properties: Size: length = 12.0 x width = Floor#: 1" 10.0, 6) Write an interface measurable that has only one method called computeAreaRoom (). 7) The class Room has to implement the interface measurable. 8) Write a subclass of the class Room called Classroom, which also has a private instance variable of type int called numStudents, representing the maximum number of students that the classroom can hold. 9) Write a constructor for Classroom which takes in two double variables and two ints. The instance variable length should be set to the larger double, and the width should be set to the smaller double as in Room. The instance variable floor should be set to the first int, and the instance variable numStudents should be set to the second int. Leave the instance variables as private in Room and use setters to access them. 10) Override toString method for Classroom which uses the toString method for Room, followed by an additional String: Type: classroom Capacity: numStudents students" where numStudents is replaced by the instance variable value. 11) Write a subclass of the class Room called officeroom, which also has a private instance variable of type int called numEmployee, representing the maximum number of employees that the officeroom can hold. 12) Write a constructor for officeroom which takes in two double variables and two ints. The instance variable length should be set to the larger double, and the width should be set to the smaller double as in Room. The instance variable floor should be set to the first int, and the instance variable numEmployee should be set to the second int. Leave the instance variables as private in Room and use setters to access them. 13) Override the toString method for officeroom which uses the toString method for Room, followed by an additional String: Type: office Capacity: numEmployee empoyees. where numEmployee is replaced by the instance variable value. 14) Write the class RoomsDemo with the main method, and follow the instructions bellow: a) Declare an array called rooms of three objects of type Room [] rooms =new [3]; b) Assign to the first element of the array an object of type Room with: width=8, length=15 and floor =1. Rooms [. -] = new c) Assign to the second object an object of type Classroom with: width=30, length=50, floor =2 and 20 students. Rooms [... -] = new d) Assign to the third object an object of type Officeroom with: width=20, length=25, floor =3 and 3 employees. Rooms [. -] = new e) Use a for loop to get the following output (do not forget to display the areas): Room properties: Size: length = 15.0 x width = 8.0. - Floor#: 1 Area: 120.0 square feet. Room properties: Size: length = 50.0 x width = 30.0. Floor#: 2 Type classroom Capacity: 20 students Area: 1500.0 square feet. Room properties: Size: length = 25.0 x width 25.0 x width = 20.0. - Floor#: 3 -Type: office Capacity: 3 empoyees. Area: 500.0 square feet. 1) Write a class called Room, which has three private instance variables: a) a double width, representing the width of the room in feet, b) a double length, representing the length of the room in feet, and c) an int floor, representing the building floor that the room is on. 2) Write a default constructor for the class Room that sets the width to 10, the length to 12.5, and the floor to 1. 3) Write get and set methods ("getters" and "setters") for the three instance variables. For the set methods for the width and length, only positive values should be set. If the input is 0 or a negative number, the variables should not be changed. 4) Write a constructor for the class Room that takes in two double parameters and an int, and sets length to the larger double, width to the smaller double, and floor to the int. Use the setters from part (b). 5) Override the default toString method for the class Room, so when called by an instance of Room created by the default constructor from part (a) would return the String: "Room properties: Size: length = 12.0 x width = Floor#: 1" 10.0, 6) Write an interface measurable that has only one method called computeAreaRoom (). 7) The class Room has to implement the interface measurable. 8) Write a subclass of the class Room called Classroom, which also has a private instance variable of type int called numStudents, representing the maximum number of students that the classroom can hold. 9) Write a constructor for Classroom which takes in two double variables and two ints. The instance variable length should be set to the larger double, and the width should be set to the smaller double as in Room. The instance variable floor should be set to the first int, and the instance variable numStudents should be set to the second int. Leave the instance variables as private in Room and use setters to access them. 10) Override toString method for Classroom which uses the toString method for Room, followed by an additional String: Type: classroom Capacity: numStudents students" where numStudents is replaced by the instance variable value. 11) Write a subclass of the class Room called officeroom, which also has a private instance variable of type int called numEmployee, representing the maximum number of employees that the officeroom can hold. 12) Write a constructor for officeroom which takes in two double variables and two ints. The instance variable length should be set to the larger double, and the width should be set to the smaller double as in Room. The instance variable floor should be set to the first int, and the instance variable numEmployee should be set to the second int. Leave the instance variables as private in Room and use setters to access them. 13) Override the toString method for officeroom which uses the toString method for Room, followed by an additional String: Type: office Capacity: numEmployee empoyees. where numEmployee is replaced by the instance variable value. 14) Write the class RoomsDemo with the main method, and follow the instructions bellow: a) Declare an array called rooms of three objects of type Room [] rooms =new [3]; b) Assign to the first element of the array an object of type Room with: width=8, length=15 and floor =1. Rooms [. -] = new c) Assign to the second object an object of type Classroom with: width=30, length=50, floor =2 and 20 students. Rooms [... -] = new d) Assign to the third object an object of type Officeroom with: width=20, length=25, floor =3 and 3 employees. Rooms [. -] = new e) Use a for loop to get the following output (do not forget to display the areas): Room properties: Size: length = 15.0 x width = 8.0. - Floor#: 1 Area: 120.0 square feet. Room properties: Size: length = 50.0 x width = 30.0. Floor#: 2 Type classroom Capacity: 20 students Area: 1500.0 square feet. Room properties: Size: length = 25.0 x width 25.0 x width = 20.0. - Floor#: 3 -Type: office Capacity: 3 empoyees. Area: 500.0 square feet.
Expert Answer:
Answer rating: 100% (QA)
Heres the implementation of the requested classes Measurable interface interface Measurable double computeAreaRoom Room class class Room implements Me... View the full answer
Posted Date:
Students also viewed these programming questions
-
Payroll System Using Inheritance and Polymorphism (oops c++), You need to implement the following harder file and classes. 1. Define the following constants in a header file called Employee.h...
-
Compare the multiple inheritance of C++ with that provided by interfaces in Java.
-
Polymorphism implies that each different MHC protein binds a different peptide motif. For the MHC class I polymorphisms, how many different MHC proteins are expressed in an individual? By the entire...
-
A common stock pays an annual dividend that increases by 4% annually and sells for $35 per share. If the market rate of return on this stock is 8%. What is the amount of the ?last dividend paid $1.53...
-
Assume a company's January 1, 2009, financial position was: Assets, $150,000 and Liabilities, $60,000. During January 2009, the company completed the following transactions: (A) Paid on a note...
-
According to the U.S. Bureau of the Census, Current Population Reports 2013, the mean and median income for households with health insurance was $86,431 and $66,000, respectively. For households...
-
What are the main similarities and differences between BS 7750, EMAS and ISO 14001? Is one of these systems to be preferred over the other two?
-
1. What will happen to the value of the U.S. dollar if oil producers decide to invest most of their earnings from oil sales in domestic infrastructure projects? 2. What factors determine the relative...
-
Banshee Ltd issues $12 million in 8-year, 8%, semi-annual coupon debentures. The rate of return required by the market is 12%. What is the journal entry to record the first payment of interest...
-
A 12.75-year maturity zero-coupon bond selling at a yield to maturity of 8% (effective annual yield) has convexity of 150.3 and modified duration of 11.81 years. A 30-year maturity 6% coupon bond...
-
Write a program that asks the user to input the number of students of a class named BIS 1003. The program then will ask the user to input: the ID, Assignment 1 marks, Assignment 2 marks and Final...
-
If cosine, theta, equals, start fraction, 4, divided by, square root of, 26, end square root, end fractioncos= 26 4 and angle theta is in Quadrant I, what is the exact value of tangent, 2, thetatan2...
-
Fast Rail Bhd. is a public company engaged in public transportation railway project. Due to the new MRT project, the company plans to raise additional financing with the issuance of RM50 million to...
-
(2) Let f R R be uniformly continuous on all of R, and define a sequence of functions by fn(x) = f(x+1/n). Show that fn uniformly.
-
Manage communication barriers between employees to ensure effective communication, which is crucial for a harmonious and productive workplace. Recognize and reward employees who make an effort to...
-
a firm generated revenues of 4,764,000 during the most recent quarter, had total expenses of 4144680 and paid dividends of 253921. in the common size income statement. What would be the quarter net...
-
The DNA sequence shown is found in the middle of a gene. If this is the coding strand, which reading frame(s) is the most likely to be the one used for this gene? and what are the first three amino...
-
Find the reduced echelon form of each of the matrices given in Problems 120. c 1 26 + 4
-
Describe the relationship between the main processor and coprocessor in a system with which you are familiar or one that you discover through Web research.
-
The instruction set of a certain processor does not have the JLE, JLT, JGE (jump less equal, less than, and greater or equal), and JGT instructions. Assume the process does not have all other...
-
Discuss the possibility of an n-address machine, where n > 3.
Study smarter with the SolutionInn App