Assume the existence of a Building class. Define a subclass, ApartmentBuilding that contains the following instance variables: an integer, numFloors, an integer, unitsPerFloor, a boolean, hasElevator, a boolean, hasCentralAir, and a string , managingCompany containing the name of the real estate company managing the building. There is a constructor containing parameters for the initialization of the above variables (in the same order as they appear above). There are also two methods: the first, getTotalUnits, accepts no parameters and returns the total number of units in the building; the second, isLuxuryBuilding accepts no parameters and returns true if the building has central air, an elevator and 2 or less units per floor.

LANGUAGE: JAVA

CHALLENGE:

Assume the existence of a Building class. Define a subclass, ApartmentBuilding that contains the following instance variables: an integer, numFloors, an integer, unitsPerFloor, a boolean, hasElevator, a boolean, hasCentralAir, and a string , managingCompany containing the name of the real estate company managing the building. There is a constructor containing parameters for the initialization of the above variables (in the same order as they appear above). There are also two methods: the first, getTotalUnits, accepts no parameters and returns the total number of units in the building; the second, isLuxuryBuilding accepts no parameters and returns true if the building has central air, an elevator and 2 or less units per floor.

SOLUTION:

public class ApartmentBuilding extends Building {
   private int numFloors, unitsPerFloor;
   private boolean hasElevator, hasCentralAir;
   private String managingCompany;
   public ApartmentBuilding(int numFloors, int unitsPerFloor, boolean    hasElevator, boolean hasCentralAir, String managingCompany) {
      this.numFloors = numFloors;
      this.unitsPerFloor = unitsPerFloor;
      this.hasElevator = hasElevator;
      this.hasCentralAir = hasCentralAir;
      this.managingCompany = managingCompany;
   }

   public int getTotalUnits() {
      return unitsPerFloor * numFloors;
   }

   public boolean isLuxuryBuilding() {
      if (unitsPerFloor <= 2 &amp;&amp; hasElevator && hasCentralAir)
         return true;
      else
         return false;
   }
}