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
We want to get an idea of how many tickets we have and what our issues are. Print the ticket ID number, ticket description, ticket priority, ticket status, and, if the information is available, employee first name assigned to it for our records. Include all tickets regardless of whether they have been assigned to an employee or not. Sort it alphabetically by ticket status, and then numerically by ticket ID, with the lower ticket IDs on top.
Figure 1 shows an ASM chart representing the operation of a controller. Stateassignments for each state are indicated in square brackets for [Q1, Q0].Using the ASM design technique:(a) Produce a State Transition Table from the ASM Chart in Figure 1.(b) Extract minimised Boolean expressions from your state transition tablefor Q1, Q0, DISPATCH and REJECT. Show all your working.(c) Implement your design using AND/OR/NOT logic gates and risingedgetriggered D-type Flip Flops. Your answer should include a circuitschematic.
A controller is required for a home security alarm, providing the followingfunctionality. The alarm does nothing while it is disarmed (‘switched off’). It canbe armed (‘switched on’) by entering a PIN on the keypad. Whenever thealarm is armed, it can be disarmed by entering the PIN on the keypad.If motion is detected while the alarm is armed, the siren should sound AND asingle SMS message sent to the police to notify them. Further motion shouldnot result in more messages being sent. If the siren is sounding, it can only bedisarmed by entering the PIN on the keypad. Once the alarm is disarmed, asingle SMS should be sent to the police to notify them.Two (active-high) input signals are provided to the controller:MOTION: Asserted while motion is detected inside the home.PIN: Asserted for a single clock cycle whenever the PIN has beencorrectly entered on the keypad.The controller must provide two (active-high) outputs:SIREN: The siren sounds while this output is asserted.POLICE: One SMS…
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