2. values. Save the application as TestSandwich.java. prompts the user for data, instantiates one Sandwich 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 default 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 get and set each of the fields. Include a nonstatic method named addPet Fee () that adds $10 to the monthly rent value and calls a static method named explainPet Policy () that explains the pet fee. Save the class as Lease.java. b. Create a class named TestLease whose main () method declares four Lease objects named leasel, lease2, lease3, and lease4. Create a getData() method that prompts a user for values for each field for a Lease, and return a newly constructed Lease object to the main () method, where it is assigned to one of main () 's first three Lease objects. Do not prompt the user for values for the fourth Lease object, but let it hold the default values. After the four Lease objects have been assigned values, pass the leasel object to a showValues () method that displays the data. Then call the addPet Fee () method with the leasel object, and confirm that the fee explanation statement is displayed. Next, call the showValues () method for the leasel object again and confirm that the pet fee has been added to the rent. Finally, call the showValues () method with each of the other three objects. Confirm that three hold the values you supplied as input and one holds the constructor default values. Save the application as TestLease.java.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
Java Programming Eclipse IDE Question 2, a and b. Help would be appreciated, Having trouble figuring this out.
**Chapter 4: Using Classes and Objects**

1. **Question and Answer Section:**

   - **16. Methods that you reference with individual objects are:**
     - a. Private
     - b. Public
     - c. Static
     - d. Nonstatic
    
   - **17. Variables that are shared by every instantiation of a class are:**
     - a. Class variables
     - b. Private variables
     - c. Public variables
     - d. Illegal
    
   - **18. The keyword `final` used with a variable declaration indicates:**
     - a. The end of the program
     - b. It is in a static method
     - c. A symbolic constant
     - d. That no more variables will be declared in the program

   - **19. Which of the following statements determines the square root of a number and assigns it to the variable `a`:**
     - a. a = sqrt(number);
     - b. a = Math.sqrt(number);
     - c. number = sqrt(s);
     - d. number = Math.sqrt(s);

   - **20. Which of the following expressions correctly returns an integer that represents the month of a `LocalDate` object named `hireDate`:**
     - a. getMonth(hireDate)
     - b. getMonthValue(hireDate)
     - c. hireDate.getMonthValue()
     - d. hireDate.setMonthValue()

2. **Programming Exercises:**

   1. **Create a class named 'Sandwich':**
      - **Data fields:** A `String` for the main ingredient (such as tuna) and a `double` for the price (such as 4.99).
      - Include methods to get and set values for each of these fields.
      - Save the class as `Sandwich.java`.
      - **Application:** Create an application named `TestSandwich` that prompts the user for data, instantiates one `Sandwich` object, and displays its values.
      - Save as `TestSandwich.java`.

   2. **Create a class named 'Lease':**
      - **Fields:** Include fields that hold an apartment tenant's name, apartment number, monthly rent amount, and term of the lease in months.
      - **Constructor:** Create a default constructor that initializes the name to "XXX", the apartment number to 0, the rent
Transcribed Image Text:**Chapter 4: Using Classes and Objects** 1. **Question and Answer Section:** - **16. Methods that you reference with individual objects are:** - a. Private - b. Public - c. Static - d. Nonstatic - **17. Variables that are shared by every instantiation of a class are:** - a. Class variables - b. Private variables - c. Public variables - d. Illegal - **18. The keyword `final` used with a variable declaration indicates:** - a. The end of the program - b. It is in a static method - c. A symbolic constant - d. That no more variables will be declared in the program - **19. Which of the following statements determines the square root of a number and assigns it to the variable `a`:** - a. a = sqrt(number); - b. a = Math.sqrt(number); - c. number = sqrt(s); - d. number = Math.sqrt(s); - **20. Which of the following expressions correctly returns an integer that represents the month of a `LocalDate` object named `hireDate`:** - a. getMonth(hireDate) - b. getMonthValue(hireDate) - c. hireDate.getMonthValue() - d. hireDate.setMonthValue() 2. **Programming Exercises:** 1. **Create a class named 'Sandwich':** - **Data fields:** A `String` for the main ingredient (such as tuna) and a `double` for the price (such as 4.99). - Include methods to get and set values for each of these fields. - Save the class as `Sandwich.java`. - **Application:** Create an application named `TestSandwich` that prompts the user for data, instantiates one `Sandwich` object, and displays its values. - Save as `TestSandwich.java`. 2. **Create a class named 'Lease':** - **Fields:** Include fields that hold an apartment tenant's name, apartment number, monthly rent amount, and term of the lease in months. - **Constructor:** Create a default constructor that initializes the name to "XXX", the apartment number to 0, the rent
Certainly! Below is the transcription of the Java code visible in the image for educational purposes.

---

# Java Programming Example: Lease Class

This Java program demonstrates the implementation of a class named `Lease` using the Eclipse IDE. The program illustrates basic class structure, member variables, a default constructor, and simple getter methods.

```java
import java.util.Scanner;
public class Lease {

    public static void main(String[] args) {

        String tenantName;
        int apartmentNumber;
        int rentAmount;
        int termLease;

        // Default constructor
        public Lease() {
            tenantName = "XXX";
            apartmentNumber = 0;
            rentAmount = 1000;
            termLease = 12;
        }

        // Getter and setter methods
        public String getTenantName() {
            return tenantName;
        }

        public int getApartmentNumber() {
            return apartmentNumber;
        }

        public int getRentAmount() {
            return rentAmount;
        }
    }
}
```

## Key Components:
- **Class Declaration**: The class is declared as `public class Lease`, making it accessible throughout the application.
- **Member Variables**: The class contains four member variables to store tenant information: `tenantName`, `apartmentNumber`, `rentAmount`, and `termLease`.
- **Default Constructor**: Initializes member variables with default values: tenant's name as "XXX", apartment number as 0, rent amount as 1000, and lease term as 12 months.
- **Getter Methods**: These methods allow external code to access private member variables:
  - `getTenantName()`: Returns the tenant's name.
  - `getApartmentNumber()`: Returns the apartment number.
  - `getRentAmount()`: Returns the rent amount.

This foundational example introduces essential concepts in Java programming, such as encapsulation, object construction, and data access through getter methods.
Transcribed Image Text:Certainly! Below is the transcription of the Java code visible in the image for educational purposes. --- # Java Programming Example: Lease Class This Java program demonstrates the implementation of a class named `Lease` using the Eclipse IDE. The program illustrates basic class structure, member variables, a default constructor, and simple getter methods. ```java import java.util.Scanner; public class Lease { public static void main(String[] args) { String tenantName; int apartmentNumber; int rentAmount; int termLease; // Default constructor public Lease() { tenantName = "XXX"; apartmentNumber = 0; rentAmount = 1000; termLease = 12; } // Getter and setter methods public String getTenantName() { return tenantName; } public int getApartmentNumber() { return apartmentNumber; } public int getRentAmount() { return rentAmount; } } } ``` ## Key Components: - **Class Declaration**: The class is declared as `public class Lease`, making it accessible throughout the application. - **Member Variables**: The class contains four member variables to store tenant information: `tenantName`, `apartmentNumber`, `rentAmount`, and `termLease`. - **Default Constructor**: Initializes member variables with default values: tenant's name as "XXX", apartment number as 0, rent amount as 1000, and lease term as 12 months. - **Getter Methods**: These methods allow external code to access private member variables: - `getTenantName()`: Returns the tenant's name. - `getApartmentNumber()`: Returns the apartment number. - `getRentAmount()`: Returns the rent amount. This foundational example introduces essential concepts in Java programming, such as encapsulation, object construction, and data access through getter methods.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY