Professional Documents
Culture Documents
A. Create a class named ApartmentLease with fields that hold tenant’s information
such as apartment number, tenant’s name, monthly rental amount, and how
many months the apartment will be rented.
Inside this class, include a constructor that initializes the apartment number to 0,
the name of tenant to “XXX”, monthly rental amount into 2000, and the number of
months the apartment will be rented to 12.
Also include methods to get and set each of the fields. Include a nonstatic
method named addCarFee() that adds Php500 to the monthly rent value and
calls a static method named explainCarPolicy() that explains the car fee. Save
the class as ApartmentLease.java.
*note: When you run this program, nothing will be displayed. You don’t have a
main method here.
B. Create a class named TestLease whose main() method declares four Lease
objects. Call a getData() method three times. Within the method, prompt a
user for values for each field for an ApartmentLease, and return a
ApartmentLease object to the main() method where it is assigned to one of
main()’s ApartmentLease objects.
DO NOT prompt the user for values for the fourth ApartmentLease object, but let
it continue to hold the default values. Then, in main(), pass one of the
ApartmentLease objects to a showValues() method that displays the data. Then
call the addCarFee() method using the passed ApartmentLease object and
confirm that the fee explanation statement is displayed. Next, call the
showValues() method for the ApartmentLease object again and confirm that the
car fee has been added to the rent. Finally, call the showValues() method with
each of the other three objects; confirm that two hold the values you supplied as
input and one holds the constructor default values. Save the application as
TestLease.java.
Mutator methods
• Methods that set or change field values
• Often called setters, and they conventionally start
with the prefix set.
• Using these three-letter prefixes with your method
names is not required, but it is conventional
Accessor methods
• Methods that retrieve values
• Often called getters, and they conventionally start
with the prefix get.
• Using these three-letter prefixes with your method
names is not required, but it is conventional
Additional notes:
• You cannot use a nonstatic method without an object.
• The keyword static is used for classwide methods, but
not for methods that “belong” to objects.
Return type is
ApartmentLease