Question: I have to write a code to create a class that models a Door object. But I have to use a program code already given

I have to write a code to create a class that models a Door object. But I have to use a program code already given to me.

How do I do this??

Here is my code:

public class Lab5Door {

// To be filled in later

//instance variables

String name;

String state;

String open="open";

String closed="closed";

void Door() {

}

public static void main(String[] args) {

}

//constructors and methods to be filled i later

public void Door (String name, String state) {

setname(name);

setstate(state);

}

public String getName() {

return getName();

}

public void setstate(String state) {

this.state = state;

}

public void setname(String name) {

this.name=name;

}

public String getstate() {

return state;

}

public String open() {

state = "open";

return state;

}

public String closed() {

state = "closed";

return state;

}

}

Here is the program code:

/** /** A class to test the Door class. */ public class Lab5 { /** Tests the methods of the Door class @param args not used */ public static void main(String[] args) { // Create a Door object, frontDoor which is initially open Door frontDoor = new Door("Front", "open"); System.out.println("The front door is " + frontDoor.getState()); System.out.println("Expected: open"); // Create a second Door object, backDoor which is initially closed Door backDoor = new Door("Back", "closed"); System.out.println("The back door is " + backDoor.getState()); System.out.println("Expected: closed"); // Use the mutator to change the state variable of the backDoor object backDoor.setState("open"); System.out.println("The back door is " + backDoor.getState()); System.out.println("Expected: open"); // Use the mutator to change the name variable of the backDoor object backDoor.setName("Kitchen"); System.out.println("The back door is called " + backDoor.getName()); System.out.println("Expected: Kitchen"); // Complete the class as described in Part 8 of the Assignment } } 

How do I combine the two??

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!