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
Create a class named Lease with fields that hold an apartment tenant’s name, apartmentnumber, monthly rent amount, and term of the lease in months. Include a constructor thatinitializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to12. Also include methods to get and set each of the fields. Include a nonstatic methodnamed addPetFee() that adds $10 to the monthly rent value and calls a static methodnamed explainPetPolicy() that explains the pet fee. Save the class asLeaseYourlastname.java. Replace ‘Yourlastname’ with your real last name.b) Create a class named TestLease whose main() method declares four Lease objects. Call agetData() method three times. Within the method, prompt a user for values for each fieldfor a Lease, and return a Lease object to the main() method where it is assigned to one ofmain()’s Lease objects. Do not prompt the user for values for the fourth Lease object, but letit continue to hold the default values. Then, in main(), pass…
Write a class to represent a thermometer. The class must provide aparameterless constructor that initializes the temperature of the thermometer to37o Celsius (the average human body temperature). Store the temperature as afield in the celsius scale.Your class should provide methods to get and set the temperature using degreesCelsius, Fahrenheit, or Kelvin. For example, assume that the Celsius methodmay be used to set the temperature to 100oC. If the method to get thetemperature in Fahrenheit is called, it should return 212 (the equivalent of100oC). If the Fahrenheit method is used to set the temperature to 32oF, then themethod to retrieve the temperature in degrees Kelvin should return 273.15.To be clear, your thermometer keeps track of one temperature value (that youmay store using any scale that you like). It provides methods to set and retrievethe value using any of the three scales.Make sure to include a toString method that prints the current temperature inall 3 scales. Update…
Write a class, AgeMessages , which does the following:a. Ask the user to enter age using a Scannerb. If the age is less than 13, print: “too young to create a Facebook account”c. If the age is less than 16, print: “too young to get a driver's license”d. If the age is less than 18, print: “too young to get a tattoo”e. If the age is less than 21, print: “too young to drink alcohol”f. If the age is less than 35, print: “too young to run for President of the U.S.” and on nextline print: “(How sad!)”g. If the age is greater and equal to 35, print: “able to do anything” and on next line print:“(How happy!)”Tips Use an if statementSubmission Copy and paste your code Screen shot the console with user input of 2 Screen shot the console with user input of 18 Screen shot the console with user input of 91
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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage