Java Programming
Java Programming
9th Edition
ISBN: 9780357616635
Author: Joyce Farrell
Publisher: CENGAGE L
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
make a screen capture showing the StegExpose results
Which of the following is not one of the recommended criteria for strategic objectives? Multiple Choice   a) realistic   b) appropriate   c) sustainable   d) measurable
Management innovations such as total quality, benchmarking, and business process reengineering always lead to sustainable competitive advantage because everyone else is doing them. a) True b) False
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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning