Residence Class
The constructor takes an int for number of rooms, an int for number of external walls, and a boolean for whether or not there is a washer.
Residence also has 4 methods:
-
hasWasher()
, which returns a boolean. It returns whether or not there is a washer in the residence. This method should be protected.
As a reminder, public members and methods are accessible
from any class, while private members and methods are only
accessible from within the class in which they are declared. The
protected keyword can be thought of as midway between
public
and private
. Classes that do not either inherit
from (using extends
) a class with a protected
item
and do not exist in the same package may not access it.
Because protected
members are visible from anywhere in the same package, it is
only more secure than public
when multiple packages are used.
(See this tutorial
for more information.)
-
propertyValue()
, which returns a double. It calculates the property value based on number of rooms * 10000. -
numWindows()
, which returns an int. It calculates the number of windows based on the number of external walls * 2. -
toString()
, which returns a string containing the number of rooms, the number of walls, whether or not there is a washer, the number of windows, and the property value.
The output of toString()
should be similar to the following.
Number of Rooms: 4 Number of Walls: 4 Washer: true Number of Windows: 8 Property Value: 40000.0