In: Computer Science
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 a 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. Save the application as TestLease.java.
Note : I Provided the complete code what you required.I will also provide the output of the program.I will Update with output.
________________________
// Lease.java
public class Lease {
private String tenantName;
private int apprtNum;
private double monthlyRent;
private int leaseTerm;
private final double PETFEE = 10.0;
public Lease() {
this.tenantName="XXX";
this.apprtNum=0;
this.monthlyRent=1000;
this.leaseTerm=12;
}
public Lease(String tenantName, int apprtNum, double
monthlyRent,
int leaseTerm)
{
this.tenantName = tenantName;
this.apprtNum = apprtNum;
this.monthlyRent =
monthlyRent;
this.leaseTerm = leaseTerm;
}
public String getTenantName() {
return tenantName;
}
public void setTenantName(String tenantName)
{
this.tenantName = tenantName;
}
public int getApprtNum() {
return apprtNum;
}
public void setApprtNum(int apprtNum) {
this.apprtNum = apprtNum;
}
public double getMonthlyRent() {
return monthlyRent;
}
public void setMonthlyRent(double monthlyRent)
{
this.monthlyRent =
monthlyRent;
}
public int getLeaseTerm() {
return leaseTerm;
}
public void setLeaseTerm(int leaseTerm) {
this.leaseTerm = leaseTerm;
}
public void addPetFee() {
double newRent = this.monthlyRent +
this.PETFEE;
String ppolicy =
displayPetFeePolicy() + " " + PETFEE;
}
private static String displayPetFeePolicy() {
String str = "As You are having pet
, The Following amount has been added to your rent $";
return str;
}
}
_______________________
// TestLease.java
import java.util.Scanner;
public class TestLease {
public static void main(String[] args) {
Lease lease1=new Lease();
Lease lease2=new Lease();
Lease lease3=new Lease();
Lease lease4=new Lease();
lease1=getData();
lease2=getData();
lease3=getData();
showValues(lease1);
lease1.addPetFee();
showValues(lease1);
showValues(lease2);
showValues(lease3);
showValues(lease4);
}
private static void showValues(Lease lease) {
System.out.println("Tenant Name
:"+lease.getTenantName());
System.out.println("Appartment
Number :"+lease.getApprtNum());
System.out.println("Monthly Rent
:"+lease.getMonthlyRent());
System.out.println("Terms of Lease
:"+lease.getLeaseTerm()+" months.");
}
private static Lease getData() {
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
System.out.print("Enter tenant name
:");
String tname =sc.nextLine();
System.out.print("Enter appartment number :");
int anum = sc.nextInt();
System.out.print("Enter monthly rent :");
double mrent = sc.nextDouble();
System.out.print("Enter terms of lease (in months) :");
int leaseTerms = sc.nextInt();
Lease l=new Lease(tname,anum,mrent, leaseTerms);
return l;
}
}
__________________________