Question

In: Computer Science

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!

  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

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================


public class Lease {

    private String tenantName;
    private int apartmentNumber;
    private double monthlyRent;
    private int terms;

    public Lease() {
        tenantName = "XXX";
        apartmentNumber = 0;
        monthlyRent = 1000;
        terms = 12;
    }

    public String getTenantName() {
        return tenantName;
    }

    public int getApartmentNumber() {
        return apartmentNumber;
    }

    public double getMonthlyRent() {
        return monthlyRent;
    }

    public int getTerms() {
        return terms;
    }

    public void setTenantName(String tenantName) {
        this.tenantName = tenantName;
    }

    public void setApartmentNumber(int apartmentNumber) {
        this.apartmentNumber = apartmentNumber;
    }

    public void setMonthlyRent(double monthlyRent) {
        this.monthlyRent = monthlyRent;
    }

    public void setTerms(int terms) {
        this.terms = terms;
    }

    public void addPetFee() {
        monthlyRent += 10;
    }

    public static void explainPetPolicy() {

        System.out.println("A pet fee of $10 is added to the monthly rent.");
    }
}

===========================================================

import java.util.Scanner;
public class TestLease {

    static Scanner scanner = new Scanner(System.in);

    // return a Lease object
    public static Lease getData() {

        System.out.print("Enter tenant name: ");
        String name = scanner.nextLine();
        System.out.print("Enter apartment number: ");
        int num = scanner.nextInt();
        System.out.print("Enter monthly rent: ");
        double rent = scanner.nextDouble();
        System.out.print("Enter the number of terms: ");
        int terms = scanner.nextInt();
        scanner.nextLine();

        Lease lease = new Lease();
        lease.setTenantName(name);
        lease.setApartmentNumber(num);
        lease.setMonthlyRent(rent);
        lease.setTerms(terms);

        return lease;
    }

    static void showValues(Lease lease) {

        System.out.println("Tenent name: " + lease.getTenantName());
        System.out.println("Apartment number: " + lease.getApartmentNumber());
        System.out.println("Monthly Rent: $" + lease.getMonthlyRent());
        System.out.println("Terms: " + lease.getTerms());
        System.out.println();
    }

    public static void main(String[] args) {

        Lease l1, l2, l3, l4;

        l1 = getData();
        l2 = getData();
        l3 = getData();
        l4 = new Lease();

        showValues(l1);//pass one of the Lease objects to the showValues()

        //        hen call the addPetFee() method using the passed Lease object and confirm that the fee explanation statement is displayed
        l1.addPetFee();
        l1.explainPetPolicy();

        showValues(l1); //call the showValues() method for the Lease object again


        showValues(l2);
        showValues(l3);
        //default constructor
        showValues(l4);
    }
}

===============================================================


Related Solutions

This is 1 java question with its parts. Thanks so much! Create a class named Student...
This is 1 java question with its parts. Thanks so much! Create a class named Student that 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. A Student also has a field for grade point average....
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that 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. A Student also has a field for grade point average. Include a method to compute the grade point...
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 Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
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()...
In java: -Create a class named Animal
In java: -Create a class named Animal
PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP a. Create a class named Student that has fields...
PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP a. Create a class named Student that 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. A Student also has a field for grade point average. Include a method...
This is 1 java question with 3 parts/codes called student.java, ShowStudent.java, ShowStudent2.java. Thanks so much! Create...
This is 1 java question with 3 parts/codes called student.java, ShowStudent.java, ShowStudent2.java. Thanks so much! Create a class named Student that 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. A Student also has a field...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT