Question

In: Computer Science

Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...

  1. 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.

  2. 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.

Solutions

Expert Solution

Code:-

// Lease.java
public class Lease
{
   private String tenantName;
   private int apartmentNumber;
   private double rent;
   private int termOfLease;
   Lease()
   {
       this.tenantName = "XXX";
       this.rent = 1000;
       this.apartmentNumber = 0;
       this.termOfLease = 12;
   }
   public String getTenantName()
   {
       return tenantName;
   }
   public void setTenantName(String tenantName)
   {
       this.tenantName = tenantName;
   }
   public int getApartmentNumber()
   {
       return apartmentNumber;
   }
   public void setApartmentNumber(int apartmentNumber)
   {
       this.apartmentNumber = apartmentNumber;
   }
   public double getRent()
   {
       return rent;
   }
   public void setRent(double rent)
   {
       this.rent = rent;
   }
   public int getTermOfLease()
   {
       return termOfLease;
   }
   public void setTermOfLease(int termOfLease)
   {
       this.termOfLease = termOfLease;
   }
   public void addPetFee()
   {
       this.rent += 10;
       explainPetPolicy();
   }
   public static void explainPetPolicy()
   {
       System.out.println("If you have pets, you should pay an extra rent of 10 dollars");
   }
}

// TestLease.java
import java.util.Scanner;
public class TestLease
{
   public static Lease getData()
   {
       Scanner in = new Scanner(System.in);
       Lease l = new Lease();
       System.out.print("Enter Tenant's Name: ");
       String name = in.nextLine();
       l.setTenantName(name);
       System.out.print("Enter Rent amount: ");
       double rent = in.nextDouble();
       l.setRent(rent);
       System.out.print("Enter Appartment Number: ");
       int number = in.nextInt();
       l.setApartmentNumber(number);
       System.out.print("Enter Term of lease: ");
       int term = in.nextInt();
       l.setTermOfLease(term);
       return l;
   }
   public static void showValues(Lease l)
   {
       System.out.println("Tenant's name: " + l.getTenantName());
       System.out.println("Rent Amount: " + l.getRent());
       System.out.println("Appartment Number: " + l.getApartmentNumber());
       System.out.println("Term of lease: " + l.getTermOfLease() + "\n");
   }
   public static void main(String args[])
   {
       Lease l1 = new Lease(), l2 = new Lease(), l3 = new Lease(), l4 = new Lease();
       l2 = getData();
       l3 = getData();
       l4 = getData();
       showValues(l1);
       l1.addPetFee();
       showValues(l1);
       showValues(l2);
       showValues(l3);
       showValues(l4);
   }
}

Please UPVOTE thank you...!!!


Related Solutions

In java, create a class named Contacts that has fields for a person’s name, phone number...
In java, create a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contact objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. Include javadoc...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG),...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. Create a subclass named LabCourse that adds $50 to the course fee....
This is 1 java question with its parts. Thanks! Create a class named Lease with fields...
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...
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
Write a class named ContactEntry that has fields for a person’s name, phone number and email...
Write a class named ContactEntry that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five ContactEntry objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. I repeat, NO-ARG constructors....
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects. public class DemoSalesperson { public static void...
Implement an Employee class that includes data fields to hold the Employee’s ID number, first name,...
Implement an Employee class that includes data fields to hold the Employee’s ID number, first name, last name, and hourly pay rate (use of string datatype is not allowed). Create an array of five Employee objects. Input the data in the employee array. Write a searchById() function, that ask the user to enter an employee id, if its present, your program should display the employee record, if it isn’t there, simply print the message ”Employee with this ID doesn’t exist”....
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
Design a class named Person with fields for holding a person's name, address, and telephone number(all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these...
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
Design a class named Person with fields for holding a person's name, address, and telephone number(all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT