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

a. Create a class named Lease with fields that hold an apartment tenant\'s name,

ID: 670329 • Letter: A

Question

a. 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. "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. Save the class a Lease.java.

b. 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 fo 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

This is what I have done but I keep getting errors. If possible can you explain each step. I'm stil having a hard time understanding each step even the ones I have done. I am able to get this to work if I remove the get and set from the TestLeaseClass and make everything public on the Lease Class, but I am required to use the get and set methods and make all private. I really want to have a better understanding so any info would really help. Thanks!

public class Lease

{
private String name;
private double apartmentNumber;
private double rent;
private double term;

public Lease()
{
name = "xxx";
apartmentNumber = 0;
rent = 1000;
term = 12;
}
public void setname(String nm)
{
name = nm;
}
public void setapartmentNumber(double aptnbr)
{
apartmentNumber = aptnbr;
}
public void setrent(double rnt)
{
rent = rnt;
}
public void setterm(double tm)
{
term = tm;
}
public String getname()
{
return name;
}
public double getapartmentNumber()
{
return apartmentNumber;
}
public double getrent()
{
return rent;
}
public double getterm()
{
return term;
}
public void addPetFee()
{
rent += 10;
explainPetPolicy();
}
public static void explainPetPolicy()
{
System.out.println("Pet policy ");

}

}

import java.util.Scanner;
public class TestLease
{
public static void main(String[] args)
{
Lease firstLease = new Lease();
Lease secondLease = new Lease();
Lease thirdLease = new Lease();
Lease fourthLease = new Lease();
firstLease = getdata(firstLease);
secondLease = getdata(secondLease);
thirdLease = getdata(thirdLease);
showValues(firstLease);
firstLease.addPetFee();
showValues(firstLease);
showValues(secondLease);
showValues(thirdLease);
showValues(fourthLease);

}
public static Lease getdata(Lease lease)
{

Scanner keyboard = new Scanner(System.in);
System.out.print("Enter name >> ");
lease.setname = keyboard.nextLine();


System.out.print("Enter apartment number >> ");
lease.setapartmentNumber = keyboard.nextDouble();

System.out.print("Enter rent >> ");
lease.setrent = keyboard.nextDouble();

System.out.print("Enter term >> ");
lease.setterm = keyboard.nextDouble();

return lease;

}
public static void showValues(Lease lease)
{
System.out.println("Lease name " + lease.getname);
System.out.println("Lease apartment number " + lease.getapartmentNumber);
System.out.println("Lease rent " + lease.getrent);
System.out.println("Lease term " + lease.getterm);
}

}

Explanation / Answer

import java.util.Scanner;
class Lease

{
private String name;
private double apartmentNumber;
private double rent;
private double term;

public Lease()
{
name = "xxx";
apartmentNumber = 0;
rent = 1000;
term = 12;
}
public void setname(String nm)
{
name = nm;
}
public void setapartmentNumber(double aptnbr)
{
apartmentNumber = aptnbr;
}
public void setrent(double rnt)
{
rent = rnt;
}
public void setterm(double tm)
{
term = tm;
}
public String getname()
{
return name;
}
public double getapartmentNumber()
{
return apartmentNumber;
}
public double getrent()
{
return rent;
}
public double getterm()
{
return term;
}
public void addPetFee()
{
rent += 10;
explainPetPolicy();
}
public static void explainPetPolicy()
{
System.out.println("Pet policy ");

}

}

class TestLease
{
public static void main(String[] args)
{
Lease firstLease = new Lease();
Lease secondLease = new Lease();
Lease thirdLease = new Lease();
Lease fourthLease = new Lease();
firstLease = getdata(firstLease);
secondLease = getdata(secondLease);
thirdLease = getdata(thirdLease);
showValues(firstLease);
firstLease.addPetFee();
showValues(firstLease);
showValues(secondLease);
showValues(thirdLease);
showValues(fourthLease);

}
public static Lease getdata(Lease lease)
{

Scanner keyboard = new Scanner(System.in);
System.out.print("Enter name >> ");
lease.setname(keyboard.nextLine());


System.out.print("Enter apartment number >> ");
lease.setapartmentNumber(keyboard.nextDouble());

System.out.print("Enter rent >> ");
lease.setrent(keyboard.nextDouble());

System.out.print("Enter term >> ");
lease.setterm(keyboard.nextDouble());

return lease;

}
public static void showValues(Lease lease)
{
System.out.println("Lease name " + lease.getname());
System.out.println("Lease apartment number " + lease.getapartmentNumber());
System.out.println("Lease rent " + lease.getrent());
System.out.println("Lease term " + lease.getterm());
}

}

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