Question

In: Computer Science

Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method...

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.

Solutions

Expert Solution

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

}
__________________________


Related Solutions

Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of...
Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of miles, passes the value to a method that converts the value to kilometers, and then returns the value to the Main() method where it is displayed.
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
Using C# Create a class named Inches To Feet. Its Main()method holds an integer variable named...
Using C# Create a class named Inches To Feet. Its Main()method holds an integer variable named inches to which you will assign a value. Create a method to which you pass inches. The method displays inches in feet and inches. For example, 67 inches is 5 feet 7 inches.
Create a class using C# named InchesToFeet. Its Main()method holds an integer variable named inches to...
Create a class using C# named InchesToFeet. Its Main()method holds an integer variable named inches to which you will assign a value. Create a method to which you pass inches. The method uses 2 ref parameters: feet, inches left of type int and a parameter that is not ref of type int to which you pass inchesinches. For example, 67 inches is 5 feet 7 inches.
Create a C# program named SalesLetter whose Main() method uses several WriteLine() calls to display a...
Create a C# program named SalesLetter whose Main() method uses several WriteLine() calls to display a sales letter to prospective clients for a business of your choice. Display your contact information at least three times in the letter. The contact information should contain at least three lines with data such as land line phone number and/or cellphone number, email address, and web address.. Each time you want to display the contact information, call a method namedDisplayContactInfo().
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user to enter a short sentence which ends in a period. Use Java String class methods to determine the following about the sentence and display in the console: • How many total characters are in the sentence? • What is the first word of the sentence? Assume the words are separated by a space. • How many characters are in the first word of the...
Design a Java program named LambdaTester2 which includes a main method that declares a lambda expression...
Design a Java program named LambdaTester2 which includes a main method that declares a lambda expression reference which implements the following interface: interface Multiplier {     int multiply(int num1, int num2); } The program must declare an array of Pair objects (see class specification below), followed by the declaration of an ArrayList which is instantiated using the declared array (the ArrayList stores Pair objects). Then write a loop which iterates through each element of the ArrayList, calls the lambda expression reference...
Multi-Dimensional Arrays Create main class named MultiArray.    Create a method which outputs (prints) all the values...
Multi-Dimensional Arrays Create main class named MultiArray.    Create a method which outputs (prints) all the values in the array. Call this method from each of the other methods to illustrate the data in the array. Note: Be sure to populate, and update the values in the multi-array, and then print the contents of the multi-array (Don't just print the design patterns.) The goal is to practice navigating the multi-array. Declare a multi-dimensional array of integers, which is 10 rows of...
Create a generic method to print objects in java. Include a tester class.
Create a generic method to print objects in java. Include a tester class.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT