Question: I have a exericse problem in my Java Programmin book and this is what the problem wants me to do. Create a class named TestLease

I have a exericse problem in my Java Programmin book and this is what the problem wants me to do.

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 p the user 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 object,s to a showValues( ) method that displays the data. Then call the addPetFee( ) method sing the passed Lease object and confirm that the fee expalnation statement is displayed. Next, call the showValues() method for the Lease object again and confirm that the pet fee has benn 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 made in netbeans so far.

package testlease;

import java.util.Scanner;

public class TestLease {

/**

* @param args the command line arguments

*/

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);

showValues(lease1);

showValues(lease2);

showValues(lease3);

showValues(lease4);

}

public static void showValues(Lease lease1)

{

System.out.println("tenant name is. " + lease1.getName());

System.out.println("Apartment Number is. " + lease1.getApartmentNumber());

System.out.println("Your total Rent is. " + lease1.getMontlyRent());

System.out.println("Your total lease month is. " + lease1.getLease());

lease1.addPetFee();

}

public static Lease getData()

{

Scanner inputDevice = new Scanner(System.in);

Lease lease = new Lease();

System.out.println("Please Enter Name. >> ");

String name = inputDevice.nextLine();

System.out.println("Please Enter Apartment Number. >> ");

int apartmentNum = inputDevice.nextInt();

System.out.println("Please Enter Amount of Rent. >> ");

int rent = inputDevice.nextInt();

System.out.println("Please Enter Number of Months. >> ");

int months = inputDevice.nextInt();

lease.setName(name);

lease.setApartmentNumber(apartmentNum);

lease.setMontlyRent(rent);

lease.setLease(months);

return lease;

}

public static void addPetFee()

{

int TotalRent = 1000 + 10;

System.out.println(" Your Rent will be $" + TotalRent + " with the pet fee already added. ");

}

package testlease;

import java.util.Scanner;

public class TestLease {

/**

* @param args the command line arguments

*/

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);

showValues(lease1);

showValues(lease2);

showValues(lease3);

showValues(lease4);

}

public static void showValues(Lease lease1)

{

System.out.println("tenant name is. " + lease1.getName());

System.out.println("Apartment Number is. " + lease1.getApartmentNumber());

System.out.println("Your total Rent is. " + lease1.getMontlyRent());

System.out.println("Your total lease month is. " + lease1.getLease());

lease1.addPetFee();

}

public static Lease getData()

{

Scanner inputDevice = new Scanner(System.in);

Lease lease = new Lease();

System.out.println("Please Enter Name. >> ");

String name = inputDevice.nextLine();

System.out.println("Please Enter Apartment Number. >> ");

int apartmentNum = inputDevice.nextInt();

System.out.println("Please Enter Amount of Rent. >> ");

int rent = inputDevice.nextInt();

System.out.println("Please Enter Number of Months. >> ");

int months = inputDevice.nextInt();

lease.setName(name);

lease.setApartmentNumber(apartmentNum);

lease.setMontlyRent(rent);

lease.setLease(months);

return lease;

}

public static void addPetFee()

{

int TotalRent = 1000 + 10;

System.out.println(" Your Rent will be $" + TotalRent + " with the pet fee already added. ");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!