Question

In: Computer Science

Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...

  1. 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 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 addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy() that explains the pet fee as folows: A pet fee of $10 is added to the monthly rent.

  2. Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method three times. Within the method, prompt a user for values for each field for a Lease, and return a Lease object to the main() method where it is assigned to one of main()’s Lease objects. Do not prompt the user for values for the fourth Lease object, but let it continue to hold the default values. Then, in main(), pass one of the Lease objects to the showValues() method that displays the data. Then call the addPetFee() method using the passed Lease object and confirm that the fee explanation statement is displayed. Next, call the showValues() method for the Lease 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 two hold the values you supplied as input and one holds the constructor default values.

EDIT: This is for Java.

Solutions

Expert Solution

The program is given below: that contain class Lease with fields apartment_name, apartment_no, rent_amount, term_lease_month, default constructor, get set method for each field, addPetFee() method, explainPetPolicy() method. The program is tested by creating class TestLease.

import java.util.*;
class Lease{
String apartment_name;
int apartment_no;
double rent_amount,term_lease_month;
//default constructor
public Lease()
{
apartment_name="XXX";
apartment_no=0;
rent_amount=1000;
term_lease_month=12;
}
//get_apartment_name() method return apartment_name
public String get_apartment_name()
{
return apartment_name;
}
//get_apartment_no() method return apartment_no
public int get_apartment_no()
{
return apartment_no;
}
//get_rent_amount() method return rent_amount
public double get_rent_amount()
{
return rent_amount;
}
//get_term_lease_month() method return term_lease_month
public double get_term_lease_month()
{
return term_lease_month;
}
//set_apartment_name() method set apartment_name
public void set_apartment_name(String apartment_name)
{
this.apartment_name=apartment_name;
}
//set_apartment_no() method set apartment_no
public void set_apartment_no(int apartment_no)
{
this.apartment_no=apartment_no;
}
//set_rent_amount() method set rent_amount
public void set_rent_amount(double rent_amount)
{
this.rent_amount=rent_amount;
}
//set_term_lease_month() method set term_lease_month
public void set_term_lease_month(double term_lease_month)
{
this.term_lease_month=term_lease_month;
}
//addPetFee() method add $10 to monthly rent_amount
public void addPetFee()
{
this.rent_amount=this.rent_amount+10;
//call explainPetPolicy() method
explainPetPolicy();
}
//explainPetPolicy() method print statement regarding pet fee
public static void explainPetPolicy()
{
System.out.println("A pet fee of $10 is added to the monthly rent.");
}
}
public class TestLease
{
//getData() method take each field of Lease from user & return Lease Object
public static Lease getData()
{
Lease l=new Lease();
Scanner sc=new Scanner(System.in);
//take apartment_name from user
System.out.print("\nEnter apartment name: ");
l.apartment_name=sc.nextLine();
//take apartment_no from user
System.out.print("Enter apartment no: ");
l.apartment_no=sc.nextInt();
//take rent_amount from user
System.out.print("Enter monthly rent amount: ");
l.rent_amount=sc.nextDouble();
//take term_lease_month from user
System.out.print("Enter term of the lease in months: ");
l.term_lease_month=sc.nextDouble();
//return object
return l;
}
//showValues() method print data
public static void showValues(Lease l) {
System.out.println("\nApartment name: "+l.apartment_name);
System.out.println("Apartment no: "+l.apartment_no);
System.out.println("Monthly rent amount: "+l.rent_amount);
System.out.println("Term of the lease in months: "+l.term_lease_month);
}
   public static void main(String[] args) {
   //decare 4 Lease object
   Lease l1;
   Lease l2;
   Lease l3;
   Lease l4;
  
   //call getData() method
   l1=getData();
   l2=getData();
   l3=getData();
  
   //call showValues()
   showValues(l1);
   //call addPetFee() method
   l1.addPetFee();
   //call showValues()
   showValues(l1);
  
   l4=new Lease();
   //call showValues()
   showValues(l2);
   showValues(l3);
   showValues(l4);
   }
}

The screenshot of code is given below:

Output:


Related Solutions

Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
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 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 addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy()...
In java, create a class named Contacts that has fields for a person’s name, phone number...
In java, create a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contact objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. Include javadoc...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG),...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. Create a subclass named LabCourse that adds $50 to the course fee....
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
This is 1 java question with its parts. Thanks! Create a class named Lease with fields...
This is 1 java question with its parts. Thanks! 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 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 addPetFee() that adds $10 to the monthly...
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
Java Beginner a)Create a class named Student that has fields for an ID number, number of...
Java Beginner a)Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point average...
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
Write a class named ContactEntry that has fields for a person’s name, phone number and email...
Write a class named ContactEntry that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five ContactEntry objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. I repeat, NO-ARG constructors....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT