In: Computer Science
This is 1 java question with its parts. Thanks!
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy() that explains the pet fee as folows: A pet fee of $10 is added to the monthly rent.
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 a Lease, and return a Lease object to the main() method where it is assigned to one of main()’s Lease objects. Do not prompt the user for values for the fourth Lease object, but let it continue to hold the default values. Then, in main(), pass one of the Lease objects to the showValues() method that displays the data. Then call the addPetFee() method using the passed Lease object and confirm that the fee explanation statement is displayed. Next, call the showValues() method for the Lease object again and confirm that the pet 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.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! =========================================================================== public class Lease { private String tenantName; private int apartmentNumber; private double monthlyRent; private int terms; public Lease() { tenantName = "XXX"; apartmentNumber = 0; monthlyRent = 1000; terms = 12; } public String getTenantName() { return tenantName; } public int getApartmentNumber() { return apartmentNumber; } public double getMonthlyRent() { return monthlyRent; } public int getTerms() { return terms; } public void setTenantName(String tenantName) { this.tenantName = tenantName; } public void setApartmentNumber(int apartmentNumber) { this.apartmentNumber = apartmentNumber; } public void setMonthlyRent(double monthlyRent) { this.monthlyRent = monthlyRent; } public void setTerms(int terms) { this.terms = terms; } public void addPetFee() { monthlyRent += 10; } public static void explainPetPolicy() { System.out.println("A pet fee of $10 is added to the monthly rent."); } }
===========================================================
import java.util.Scanner;
public class TestLease { static Scanner scanner = new Scanner(System.in); // return a Lease object public static Lease getData() { System.out.print("Enter tenant name: "); String name = scanner.nextLine(); System.out.print("Enter apartment number: "); int num = scanner.nextInt(); System.out.print("Enter monthly rent: "); double rent = scanner.nextDouble(); System.out.print("Enter the number of terms: "); int terms = scanner.nextInt(); scanner.nextLine(); Lease lease = new Lease(); lease.setTenantName(name); lease.setApartmentNumber(num); lease.setMonthlyRent(rent); lease.setTerms(terms); return lease; } static void showValues(Lease lease) { System.out.println("Tenent name: " + lease.getTenantName()); System.out.println("Apartment number: " + lease.getApartmentNumber()); System.out.println("Monthly Rent: $" + lease.getMonthlyRent()); System.out.println("Terms: " + lease.getTerms()); System.out.println(); } public static void main(String[] args) { Lease l1, l2, l3, l4; l1 = getData(); l2 = getData(); l3 = getData(); l4 = new Lease(); showValues(l1);//pass one of the Lease objects to the showValues() // hen call the addPetFee() method using the passed Lease object and confirm that the fee explanation statement is displayed l1.addPetFee(); l1.explainPetPolicy(); showValues(l1); //call the showValues() method for the Lease object again showValues(l2); showValues(l3); //default constructor showValues(l4); } }
===============================================================