Q: Assume the existence of a Building class. Define a subclass, ApartmentBuildin
ID: 3652596 • Letter: Q
Question
Q: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 Code:
public class ApartmentBuilding extends Building{
int numFloors=null;
int unitsPerFloor=null;
boolean hasElevator=null;
boolean hasCentralAir=null;
String managingCompany=null;
public set numFloors(int a){
numFloors=a;
}
public setunitsPerFloor(int b){
unitsPerFloor=b;
}
public sethasElevator(boolean c){
hasElevator=c;
}
public sethasCentralAir(boolean d){
hasCentralAir=d;
}
public setmanagingCompany(String e){
managingCompany=e;
}
public int getTotalUnits(){
int i=null;
i=numFloors*unitsPerFloor;
return i;
}
public boolean isLuxuryBuilding(){
if((hasElevator==true)&&(hasCentralAir==true))
return true;
else
return false;
}
}
Here's my compile issue:
I should be using private, and am I sure that I should use 'i' 'null' 'set'
Explanation / Answer
public class ApartmentBuilding extends Building{ int numFloors; int unitsPerFloor; boolean hasElevator; boolean hasCentralAir; String managingCompany; public void setnumFloors(int a){ numFloors=a; } public void setunitsPerFloor(int b){ unitsPerFloor=b; } public void sethasElevator(boolean c){ hasElevator=c; } public void sethasCentralAir(boolean d){ hasCentralAir=d; } public void setmanagingCompany(String e){ managingCompany=e; } public int getTotalUnits(){ int i; i=numFloors*unitsPerFloor; return i; } public boolean isLuxuryBuilding(){ if((hasElevator==true)&&(hasCentralAir==true)) return true; else return false; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.