This lab will focus primarily on the use of constructors, setters, getters, and object instances.
For ease of access, here is the javadoc.
Answer the following questions on a separate sheet of paper or in the comments of your code:
- What is a setter?
- What is a getter?
- Why do you think we have/use constructors?
- What do we call the object variables Household has of type Child, Guardian, and Dog?
For this assignment, you will see that Household and Guardian have been completed for you. You will need to complete the code in Child and Dog.
After you have finished writing your code, run the tests in main and ad a few more of your own to test your work.
Once finished, be sure to submit your code to Zybooks and make sure to get your self-explanation checked.
The "this keyword" is a very useful one. When you are working with a local variable and a class variable of the same name, you can use
this.variablename
to specify the class variable. Otherwise the local variable will be assumed.
You can think of it like this: say you work in an office and the big boss in charge is named Steve. You also have a coworker named Steve. When you mention Steve, everyone assumes you are refering to your coworker unless you specify Big Boss Steve, or this.Steve.