Question: vvt AaBbCcDdEe| AaBbCcDdee AaBbCcDc AaBbCcDdEx No Spacing Heading 1 Heading 2 Normal Task 2 - Creating Your First Class First let's create a java class

 vvt AaBbCcDdEe| AaBbCcDdee AaBbCcDc AaBbCcDdEx No Spacing Heading 1 Heading 2
Normal Task 2 - Creating Your First Class First let's create a

vvt AaBbCcDdEe| AaBbCcDdee AaBbCcDc AaBbCcDdEx No Spacing Heading 1 Heading 2 Normal Task 2 - Creating Your First Class First let's create a java class to model a very simple, everyday object: a door. Recall that a class needs instance variables + methods (including constructor). 1. Create a new class under your project called Door. 2. What instance variables are needed to describe a door object? A door object might have a name like "Front" or "Side" to distinguish it from other doors. Another property that could describe a door is its state: "open" or "closed". Declare two instance variables for your Door class. You can call them state and name. 3. Now add a constructor that initializes the instance variables. Be careful about the two special characteristics of a constructor. Assign initial state as "closed" and initial name as "Back Door". A constructor should be declared after instance variable(s) and before the other methods. 4. It is helpful to provide separate method to access each single instance variable. Here is an accessor method for the name variable: public String getName return name; What does the word String in front of getName) indicate? Something the method should return? Why is it a String? If you are not sure about the answers, ask the instructor. Add this method to the class and write a similar accessor method for the instance variable state. CS 121: Computer Programming I 5. Next we will add methods that allow user to change the value of the instance variables. Here is a setter method for the name variable: 6. public void setName(String new Name) { 8. name = new Name: The word void in front of setName() indicates that the method does not return a value when it is invoked. Add this method to the class and write a similar setter method for the instance variable state. 10. Declare methods called open and close. Make them public. Define the method header first. Both have a void return type. Implement the method body. 11. Finally, use the provided driver program (testing class) Door Tester.java to test your Door class. Add DoorTester.java to the same project. Run the program. If the expected output does not match your program output, go back to the Door class to fix the problems

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!