practicing programming with MyProgrammingLab and getting following compile error: ApartmentBuilding.java:4: error: expected
its also giving me the following hints: • You should be using: isLuxuryBuilding • Are you sure you want to use: " • Are you sure you want to use: >=
this is the requirement: 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.
my SC:
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 isLuxuyBuilding() {if(unitsPerFloor <= 2 && hasElevator >= 2 && hasCentralAir >= 2) {return true;}
else {System.err.println(managingCompany + " is not luxury");}}}
You can't use quotes in variable names
Change
private String "managingCompany";
to
private String managingCompany;
Also hasElevator
is a boolean
can't be compared to a number integer in this statement:
if (unitsPerFloor <= 2 && hasElevator >= 2 && hasCentralAir >= 2) {
The method isLuxuyBuilding
must return a boolean
. The else
statement doesnt have any return value.
You can do:
public boolean isLuxuyBuilding() {
if (unitsPerFloor <= 2 && hasElevator && hasCentralAir) {
return true;
} else {
return false;
}
}
See: Variables