Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume the existence of the Building class. Describe a subclass, ApartmentBuildi

ID: 3571630 • Letter: A

Question

Assume the existence of the Building class. Describe a subclass, ApartmentBuilding that consists of following instance variables: an integer, a boolean, numFloors, an integer, hasElevator, unitsPerFloor, a boolean, hasCentralAir, and a string, managingCompany consisting of the name of real estate company managing the building. There is a constructor having the parameters for initialization of above variables. There exist two methods: the first, getTotalUnits, accepts no parameters and returns the total number of units within building; the second, is LuxuryBuilding accepts no parameters and returns the true if building has central air, an elevator and two or less units per floor.

Explanation / Answer

Building.java

public class Building {

}

____________________

AppartmentBuilding.java

public class AppartmentBuilding extends Building {

   //Declaring instance vaiables
private   int num_Floors;
private   int units_per_floor;
private   boolean hasElevator;
private   boolean hasCentralAir;
private   String name;

//Parameterized constructor
   public AppartmentBuilding(int num_Floors, int units_per_floor,
           boolean hasElevator, boolean hasCentralAir, String name) {
       super();
       this.num_Floors = num_Floors;
       this.units_per_floor = units_per_floor;
       this.hasElevator = hasElevator;
       this.hasCentralAir = hasCentralAir;
       this.name = name;
   }
  
   //This method returns the total no of units in the appartment Building
   public int getTotalUnits()
   {
       return num_Floors*units_per_floor;
   }
  
   //This method method will check whether the appartment building is luxury building or not
   public boolean isLuxuryBuilding()
   {
       boolean bool = false;
       if(hasCentralAir==true && hasElevator==true && units_per_floor<=2)
          
           {
           bool= true;
           }
       return bool;
  
   }
  
   //Getters and setters
   public int getNum_Floors() {
       return num_Floors;
   }
   public void setNum_Floors(int num_Floors) {
       this.num_Floors = num_Floors;
   }
   public int getUnits_per_floor() {
       return units_per_floor;
   }
   public void setUnits_per_floor(int units_per_floor) {
       this.units_per_floor = units_per_floor;
   }
   public boolean isHasElevator() {
       return hasElevator;
   }
   public void setHasElevator(boolean hasElevator) {
       this.hasElevator = hasElevator;
   }
   public boolean isHasCentralAir() {
       return hasCentralAir;
   }
   public void setHasCentralAir(boolean hasCentralAir) {
       this.hasCentralAir = hasCentralAir;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
  
   //toString() method displays the contents of an object inside it
   @Override
   public String toString() {
       return "AppartmentBuilding [num_Floors=" + num_Floors
               + ", units_per_floor=" + units_per_floor + ", hasElevator="
               + hasElevator + ", hasCentralAir=" + hasCentralAir + ", name="
               + name + "]";
   }
  
}

______________________

TestClass.java

public class TestClass {

   public static void main(String[] args) {
      
       //Creating an object to the AppartmentBuilding class
AppartmentBuilding ab=new AppartmentBuilding(5, 2,true,true,"Brooks");

//Calling the method getTotalUnits() on the AppartmentBuilding object
int total_units=ab.getTotalUnits();

//Displaying the total no of units an Appartment building is having
System.out.println("Appartment Building is having total no of units :"+total_units);

//Calling the method isLuxuryBuilding() on the AppartmentBuilding object
boolean bool=ab.isLuxuryBuilding();
if(bool==true)
System.out.println("Appartment Building is Luxury Building");
else
System.out.println("Appartment Buildingis not Luxury Building");

//Displaying the contents of an Appartment building object
System.out.println(ab.toString());

   }

}

__________________________

Output:

Appartment Building is having total no of units :10
Appartment Building is Luxury Building
AppartmentBuilding [num_Floors=5, units_per_floor=2, hasElevator=true, hasCentralAir=true, name=Brooks]

_____Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote