** USING JAVA** Part 1: On the left above is the UML class diagram for the InnRo
ID: 3683247 • Letter: #
Question
** USING JAVA**
Part 1:
On the left above is the UML class diagram for the InnRoom class you created for last week’s lab. On the right is the diagram for the InnRoom class in Homework 2. Notice the differences between the two classes. For Lab 08, make a new project and create an InnRoom.java class that matches the diagram on the right. If it helps, copy your InnRoom code from last week’s project and modify that.
This is my code for the InnRoom on the left:
public class InnRoom {
private String interestingObject;
private int roomNumber;
// Contructor
public InnRoom (int rNum){
roomNumber = rNum;
}
public String getInterestingObject(){
return interestingObject;
}
public void setInterestingObject(String Object){
interestingObject = Object;
}
public int getRoomNumber(){
return roomNumber;
}
public void displayRoomDescription(){
System.out.println("In room " +roomNumber + " you see a " +interestingObject);
}
}
Part 2: Create a Program that Uses InnRoom ?
InnRoom is a class that is useful for storing and updating an interesting object and displaying a room description. That’s basically all it does. Let’s write a program that makes use of it. Here’s your problem statement:
MotelInspection.java. displays a welcome message and a report on the condition of the rooms in a nine-room motel. This program must use the new InnRoom class to store and display the room data. There is no user input.
Here is a use case of MotelInspection.java running:
You are free to get creative with your own room data in the descriptions, but the form of the output must closely match the use case provided.
If you haven’t put any code into the displayRoomDescription method yet, here’s a hint: That method doesn’t take any parameters, and it doesn’t return anything, but it should have some code in it that writes output to the console (like calls to System.out.println). You can make the room description work however you like, but it should probably use the interestingObject. One way you could do this, would be to have the following line in displayRoomDescription: System.out.println(“In this room you see ” + interestingObject);Explanation / Answer
The differences are
1) constructor has no parameter
2) room number variable and corresponding getter and setter are not there in new innroom class
package assignment;
public class MotelInspection {
public static void main(String args[]) throws InterruptedException {
String msgs[] = { "a crack in the wall", "an expired fire hydrant",
"a broken mirror", "a leak in plumbing",
" a worn and stained carper", " a wonderful painting",
" a big LCD TV", " a mini library of books",
" a flea and a bedbug" };
InnRoom rooms[] = new InnRoom[9];
for (int i = 0; i < 9; i++) {
rooms[i] = new InnRoom();
rooms[i].setInterestingObject(msgs[i]);
rooms[i].displayRoomDescription();
}
}
}
class InnRoom {
private String interestingObject;
// Contructor
public InnRoom() {
interestingObject = "";
}
public String getInterestingObject() {
return interestingObject;
}
public void setInterestingObject(String Object) {
interestingObject = Object;
}
public void displayRoomDescription() {
System.out.println("In this room you see " + interestingObject);
}
}
---output--------------
In this room you see a crack in the wall
In this room you see an expired fire hydrant
In this room you see a broken mirror
In this room you see a leak in plumbing
In this room you see a worn and stained carper
In this room you see a wonderful painting
In this room you see a big LCD TV
In this room you see a mini library of books
In this room you see a flea and a bedbug
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.