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:

The Bad News: The content you are trying to access is only available to members.

The Good News: You too can be a member, simply Click Here.

Already a member?

Posted in ,

2 Comments

  1. Basil on February 17, 2017 at 12:22 pm

    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 && hasElevator && hasCentralAir) {
    return true;
    } else {
    return false;
    }
    }
    }

  2. rebecca on March 12, 2017 at 4:32 pm

    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&& hasElevator && hasCentralAir)
    return true;
    else
    return false;
    }
    }

Leave a Comment

You must be logged in to post a comment.