Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
Publisher: Cengage Learning
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
Change the following code so that there is always at least one way to get from the left corner to the top right, but the labyrinth is still randomized. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. Take care that the player and the dragon cannot start off on walls. Also the dragon starts off from a randomly chosen position   public class Labyrinth {    private final int size;    private final Cell[][] grid;     public Labyrinth(int size) {        this.size = size;        this.grid = new Cell[size][size];        generateLabyrinth();    }     private void generateLabyrinth() {        Random rand = new Random();        for (int i = 0; i < size; i++) {            for (int j = 0; j < size; j++) {                // Randomly create walls and paths                grid[i][j] = new Cell(rand.nextBoolean());            }        }        // Ensure start and end are…
Change the following code so that it checks the following 3 conditions: 1. there is no space between each cells (imgs) 2. even if it is resized, the components wouldn't disappear 3. The GameGUI JPanel takes all the JFrame space, so that there shouldn't be extra space appearing in the frame other than the game.   Main():         Labyrinth labyrinth = new Labyrinth(10);         Player player = new Player(9, 0);        Dragon dragon = new Dragon(9, 9);         JFrame frame = new JFrame("Labyrinth Game");        GameGUI gui = new GameGUI(labyrinth, player, dragon);         frame.add(gui);        frame.setSize(600, 600);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.setVisible(true);   public class GameGUI extends JPanel {    private final Labyrinth labyrinth;    private final Player player;    private final Dragon dragon; //labyrinth, player, dragon are just public classes     private final ImageIcon playerIcon = new ImageIcon("data/images/player.png");…
Make the following game user friendly with GUI, with some simple graphics. The GUI should be in another seperate class, with some ImageIcon, and Game class should be added into the pane. The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units.  Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return…
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