EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
Expert Solution & Answer
Book Icon
Chapter 3, Problem 13PE

Explanation of Solution

a.

Program code:

Lease.java

//define the class Lease

public class Lease

{

//declare class members

private static final double PET_FEE = 10;

private String tenantName;

private int apartmentNumber;

private double monthlyRent;

private int leasePeriod;

//Default constructor

public Lease()

{

//initialize the class members

tenantName ="XXX";

apartmentNumber =0;

monthlyRent = 1000;

leasePeriod =12;

}

//getters and setters

//define a method getTenantName()

public String getTenantName()

{

//return the variable tenantName

return tenantName;

}

//define a method setTenantName()

public void setTenantName(String tenantName)

{

//set the value of tenantName

this.tenantName = tenantName;

}

//define a method getApartmentNumber()

public int getApartmentNumber()

{

//return the variable apartmentNumber

return apartmentNumber;

}

//define a method setApartmentNumber()

public void setApartmentNumber(int apartmentNumber)

{

//set the value of apartmentNumber

this.apartmentNumber = apartmentNumber;

}

//define a method getMonthlyRent()

public double getMonthlyRent()

{

//return the variable monthlyRent

return monthlyRent;

}

//define a method setMonthlyRent()

public void setMonthlyRent(double monthlyRent)

{

//set the value of monthlyRent

this.monthlyRent = monthlyRent;

}

//define a method getLeasePeriod()

public int getLeasePeriod()

{

//return the variable leasePeriod

return leasePeriod;

}

//define a method setLeasePeriod()

public void setLeasePeriod(int leasePeriod)

{

//set the value of leasePeriod

this.leasePeriod = leasePeriod;

}

//define a method addPetFee()

public void addPetFee()

{

//adds $10

monthlyRent+=PET_FEE;

}

//define a method explainPetPolicy()

public static void explainPetPolicy()

{

//print the statement

System.out.println("Add $10 to rent as pet fee.");

}

}

Explanation:

The above snippet of code is used create a class “Lease”. The class contain different static methods for store the details of a lease. In the code,

  • Define a class “Lease”
    • Declare the class members.
    • Define the constructor “Lease()” method.
      • Initialize the class members.
    • Define the “getTenantName()” method.
      • Return the value of the variable “tenantName”.
    • Define the “setTenantName()” method.
      • Set the value of the variable “tenantName”.
    • Define the “getApartmentNumber()” method.
      • Return the value of the variable “apartmentNumber”.
    • Define the “setApartmentNumber()” method.
      • Set the value of the variable “ApartmentNumber”.
    • Define the “getMonthlyRent()” method.
      • Return the value of the variable “MonthlyRent”.
    • Define the “setMonthlyRent ()” method.
      • Set the value of the variable “MonthlyRent”.
    • Define the “getLeasePeriod()” method.
      • Return the value of the variable “leasePeriod”.
    • Define the “setLeasePeriod()” method.
      • Set the value of the variable “leasePeriod”.
    • Define the “addPetFree()” method.
      • Set the value of “monthlyRent”.
    • Define the “explainPetPolicy()” method.
      • Print the statement.

b.

TestLease.java

//import the packages

import java.text.NumberFormat;

import java.util.Scanner;

//define a class TestLease

public class TestLease

{

//define main() method

public static void main(String[] args)

{

//declare the objects of the class Lease

Lease lease1 = new Lease();

Lease lease2 = new Lease();

Lease lease3 = new Lease();

Lease lease4 = new Lease();

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

Blurred answer
Students have asked these similar questions
1. Create a class named Student that has fields for an ID number (idNumber), number of credit hours earned (hours), and number of points earned (points). (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 get and set methods for all fields. A Student also has a field for grade point average. Include a getGradePoint() method to compute the grade point average field by dividing points by credit hours earned. Write methods to display the values in each Student field, showIdNumber(), showHours(), etc.   2. Use class named ShowStudent that instantiates a Student object to test your class. Compute the Student grade point average, and then display all the values associated with the Student.   3. Create a constructor for the Student class you created. The constructor should initialize each Student’s ID number to 9999, his or her points earned to 12, and credit hours to 3…
HAPTER 3 Using Methods, Classes, and Objects a. 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 13. 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. Save the class as Lease.java. b. 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…
Create a class called Point which will have 2 co-ordinate value x & y and will be able to calculate the distance between two points. Write appropriate constructor and method of the class. Create another class called Shape, which takes different number of points to create a triangle, rectangle and circle. And also able to calculate the area and perimeter for the different shapes. Write the appropriate overloading method for this shape class. Write appropriate main function to test the shape class.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,