Rental Log

Goals

In this assignment we will create classes that will help make a rental office track their tenants.

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.

  1. 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.


  2. Define a class Apartment (Apartment.java) with
    • Data: street address, and apartment number, and a Person representing the tenant ( renter) of the apartment.
    • Constructor: An apartment object is created by a constructor call with four arguments: street, street number, apartment number, and tenant (see interactions below).
    • Methods:
      • Query methods: getStreet(), getAptNumber(), and getTenant() and
      • Command method: changeTenant() that changes the apartment's owner (See interactions to get an idea on what exactly should be return type of this method).

Note: make sure that method name exactly correspond.

Here are some DrJava interactions with the classes

> Person a = new Person("Alice", 'Q', "Potter");
> a.getLastName() //String speacial object, so reference value is not printed
"Potter"
> Person b = new Person("Bob", 'B', "Little");
> Apartment s = new Apartment("2031 Spruce St", 2, a);
> s.getTenant() //Memory location where Person a is stored. Note the location value will be different on your pc
Person@aefcbb
> s.getTenant().getFirstName() //s.getTenant() returns a Person object reference
"Alice"
> s.changeTenant(b);
> s.getTenant()//The location of where Person b is stored is different than where Perosn a is stored
Person@39060b
> s.getTenant().getFirstName()
"Bob"

Draw the stack and heap memory, based on the above interactions. Click here to print the draw sheet.

Note that lot more information (data) could be added to Apartment class. Can you think of any besides what we already have?