Question

a. Create a class named Lease with fields that hold an apartment tenants name, apartment Number, monthly rent amount, and te

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

//Java code

public class Lease {
    private static final double PET_FEE = 10;
    private String tenantName;
    private int apartmentNumber;
    private double monthlyRent;
    private int leasePeriod;

    //Default constructor
    public Lease()
    {
        tenantName ="XXX";
        apartmentNumber =0;
        monthlyRent = 1000;
        leasePeriod =12;
    }
    //getters and setters

    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 getMonthlyRent() {
        return monthlyRent;
    }

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

    public int getLeasePeriod() {
        return leasePeriod;
    }

    public void setLeasePeriod(int leasePeriod) {
        this.leasePeriod = leasePeriod;
    }
    public void addPetFee()
    {
        //adds $10
        monthlyRent+=PET_FEE;
    }
    public static void explainPetPolicy()
    {
        System.out.println("Add $10 to rent as pet fee.");
    }
}

//=======================================================

import java.text.NumberFormat;
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();//leave it with default values

        //Call three times getdata()
        lease1 = getData();
        lease2 = getData();
        lease3 = getData();
        System.out.print("Display info of tenants\n\n");
        //Print info
        showValues(lease1);
        showValues(lease2);
        showValues(lease3);
        showValues(lease4);
        System.out.print("\n");
        //call the addPetFee()
        lease1.addPetFee();
        //explain pet policy
        Lease.explainPetPolicy();
        //to confirm changes
        showValues(lease1);
    }
    public static Lease getData()
    {
        Scanner scanner = new Scanner(System.in);
        Lease lease = new Lease();
        System.out.print("Enter tenant's name: ");
        lease.setTenantName(scanner.nextLine());
        System.out.print("Enter apartment number: ");
        lease.setApartmentNumber(scanner.nextInt());
        System.out.print("Enter monthly rent: $");
        lease.setMonthlyRent(scanner.nextDouble());
        System.out.print("Enter term of lease in months: ");
        lease.setLeasePeriod(scanner.nextInt());
        return lease;
    }
    public static void showValues(Lease lease)
    {
        System.out.print("\n========================\n");

        System.out.println("Tenant,s Name: "+lease.getTenantName()+"\nApartment Number: "+lease.getApartmentNumber()+"\nMonthly rent: "+ NumberFormat.getCurrencyInstance().format(lease.getMonthlyRent())+"\nTerm of Lease in month: "+lease.getLeasePeriod());
        System.out.print("\n========================\n");
    }
}

//Output

Term of Lease in month: 36 ======================== Tenant,s Name: Tom Apartment Number: 103 Monthly rent: 3,500.00 Term of L

//If you need any help regarding this solution .......... please leave a comment....... thanks

> My code has an error just after I call the data 3 times

Amanda Kuse Fri, Apr 8, 2022 2:53 PM

Add a comment
Know the answer?
Add Answer to:
a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Create a class named BankAccount with data fields for a count number and a balance. Include...

    Create a class named BankAccount with data fields for a count number and a balance. Include a constructor that takes arguments for each field. The constructor sets the balance to 0 if it is below the required $200.00 minimum for an account. Include a method that displays the account details, including an explanation if the balance was reduced to 0. Write the class TestAccount in which you instantiate two BankAccount objects, prompt a user for values of the account number...

  • Sammy’s Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists....

    Sammy’s Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. Create a Rental class for the company. The class contains: Two public final static fields that hold the number of minutes in an hour and the hourly rental rate ($40) Four private fields that hold a contract number, number of hours for the rental, number of minutes over an hour, and the price. The contract number is stored as a String because Sammy plans...

  • Design a class named Person with fields for holding a person's name, address, and telephone number...

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

  • Create a Mattress class should have fields for size (king, queen, twin), manufacturer, and price, and...

    Create a Mattress class should have fields for size (king, queen, twin), manufacturer, and price, and a constructor should set default values for each. Write set methods only for size and manufacturer. The set method for size adds $200 for king or $100 for queen. Add a toString() method that returns the data from all of the fields. A child class named AdjustableMattress extends Mattress and adds a field for adjustment type (air or mechanical), with air being the default....

  • 1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and...

    1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and onion) and price. include a constructor fhay requires arguments for borh fields ans a method to diplay the data. Create a subclass names DelicedPizza that inherits from Pizza bit adds a delivery fee and a delicery address. The description, price, and delicery address are required as arguments to the constructor. The delivery fee is $3 if the pizza ordered cost more that $15; otherwise...

  • Graded Exercise Create a class named Student. A Student has fields for an ID number, number...

    Graded Exercise Create a class named Student. A 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. A Student also has a field for grade point average. Include a method to compute the grade point...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify...

    JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. A method named getArea() that returns the area of this rectangle. design...

  • In Python - Design a class named Time. The class contains: -Data fields hour, minute, and...

    In Python - Design a class named Time. The class contains: -Data fields hour, minute, and second that represent a time. -A no-arg constructor that creates a Time object for the current time.(the values of the data fields will respresent the current time.) -A constructor that constructs a Time object with a specified hour, minute, and second, respectively. -A constructor that constructs a Time object with a specified elapsed time since midnight, Jan 1, 1970, in milliseconds. (The values of...

  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT