Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a constructor class named Lease with fields that hold an apartment tenant

ID: 3884522 • Letter: C

Question

Create a constructor class named Lease with fields that hold an apartment tenant's name, apartment number, monthly rent amount, and term of the lease (in months). Have the constructor initialize the rent amount to 800 and the term to 12. Include methods to set and get each of the fields. Include a nonstatic method named addPetFee() that adds $25 to the monthly rent amount and calls a static method named explainPetPolicy() that explains the pet fee Create a program called TestLease to input a tenant's information along with the pet fee/ Save the classes as Lease.java, TestLease.java

This is what I have but I keep getting errors in the lease.getMonthlyRent.

class Lease {
   private String tenantName;
   private int apartmentNumber;
   private int monthlyRent = 800;
   private int leaseMonths = 12;
  
   public void setName(String n) {
tenantName = n;
   }
   public void setApartmentNumber(int a) {
apartmentNumber = a;
   }
   public void setMonthlyRent(int m) {
monthlyRent = m;
   }
   public void setLease(int l) {
leaseMonths = l;
   }
   public String getName () {
return tenantName;
   }
   public int getApartmentNumber() {
return apartmentNumber;
   }
   public int getMonthlyRent() {
return monthlyRent;
   }
   public int getLease() {
return leaseMonths;
   }
   public void addPetFee() {
monthlyRent = monthlyRent + 25;
explainPetPolicy();
   }
public String explainPetPolicy() {

return " include $25 monthly pet fee";

   }
}

import java.util.*;
public class TestLease {
   public static void main (String [] args) {
   Lease lease = new Lease ();
   Scanner input = new Scanner (System.in);

   System.out.print("Tenant Name: ");
lease.setName(input.nextLine());
   System.out.print("Apartment Number: ");
lease.setApartmentNumber(input.nextInt());
   System.out.print("Lease (in months): ");
lease.setLease(input.nextInt());

   lease.setMonthlyRent(800);
   lease.addPetFee();
  
   System.out.println("Tenant " + lease.getName() + " in apartment number "
   + lease.getApartmentNumber() + " has a lease of " + lease.getLease() +
   "months. ");
   System.out.println(" The monthly rent is $" + lease.getMonthlyRent);
   System.out.println(lease.explainPetPolicy());
   }
}

Explanation / Answer

Hi,

I have modified the code and highlighted the code changes below.

TestLease.java

import java.util.*;

public class TestLease {

public static void main (String [] args) {

Lease lease = new Lease ();

Scanner input = new Scanner (System.in);

  

System.out.print("Tenant Name: ");

lease.setName(input.nextLine());

System.out.print("Apartment Number: ");

lease.setApartmentNumber(input.nextInt());

System.out.print("Lease (in months): ");

lease.setLease(input.nextInt());

  

lease.setMonthlyRent(800);

lease.addPetFee();

System.out.println("Tenant " + lease.getName() + " in apartment number "

+ lease.getApartmentNumber() + " has a lease of " + lease.getLease() +

"months. ");

System.out.println(" The monthly rent is $" + lease.getMonthlyRent());

Lease.explainPetPolicy();

}

}

Lease.java

class Lease {

private String tenantName;

private int apartmentNumber;

private int monthlyRent = 800;

private int leaseMonths = 12;

public void setName(String n) {

tenantName = n;

}

public void setApartmentNumber(int a) {

apartmentNumber = a;

}

public void setMonthlyRent(int m) {

monthlyRent = m;

}

public void setLease(int l) {

leaseMonths = l;

}

public String getName () {

return tenantName;

}

public int getApartmentNumber() {

return apartmentNumber;

}

public int getMonthlyRent() {

return monthlyRent;

}

public int getLease() {

return leaseMonths;

}

public void addPetFee() {

monthlyRent = monthlyRent + 25;

explainPetPolicy();

}

public static void explainPetPolicy () {

System.out.println("Includes additional $25 pet fee per month");

}

}

Output:

Tenant Name: Suresh
Apartment Number: 111
Lease (in months): 24
Includes additional $25 pet fee per month
Tenant Suresh in apartment number 111 has a lease of 24months.
The monthly rent is $825
Includes additional $25 pet fee per month

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote