Rental Log
The goal of this assignment is to create classes that have relationship(s) with other objects.
In this assignment we will create classes that will help make a rental office track their tenants (Rental Log).
For this problem, a person will be specified by first name, middle initial, and last name, and an apartment is specified by a street, a street number, an apartment number, and a tenant.
- Define a Java class Person (Person.java) with
- Data fields first and last names strings, the middle initial a character.
- A three-parameter constructor that creates a Person object.
- Methods: getFirstName(), getMiddleIntial(), and getLastName() that return the corresponding data values.
- Define a class Apartment (Apartment.java) with
- Data fields: immutable street, street number, and apartment number, and a mutable Person value representing the tenant (owner or renter) of the apartment.
- mutable and immutable correpond to how this data is accessible
- The street is a string, the street number and apartment number are integers.
- An apartment object is created by a constructor call with four arguments: street, street number, apartment number, and tenant.
- The Apartment class has:
- Query methods: getStreet(), getStreetNmber(), getAptNumber(), and getTenant() and
- Command method: changeTenant() that changes the apartment's owner.
Note: make sure that method name exactly correspond.
Here are some DrJava interactions with the classes
> Person a = new Person("Alice", 'Q', "Public");
> a.getLastName()
"Public"
> Person b = new Person("Bob", 'B', "Little");
> Apartment s = new Apartment("Spruce", 333, 2, a);
> s.tenant().getfirstName()
"Alice"
> s.changeTenant(b);
> s.tenant().getFirstName()
"Bob"