The code below includes a live TreeHouse variable, danasHouse, which you cannot
ID: 3788251 • Letter: T
Question
The code below includes a live TreeHouse variable, danasHouse, which you cannot see. Using commands that are described in the TreeHouse API, write one or several lines of code that will print to the console a boolean value, true or false, depending on whether danasHouse is dangerous.
width
Tree house width
length
Tree house length
heightAboveGround
Tree house height above ground
treeKind
Tree house kind of tree, e.g. maple
TreeHouse
the tree house constructor
Parameters:
theWidth - the width of the house
theLength - the length of the house
theHeight - the height of the house above ground
tree - the kind of tree
getWidth
Gives tree house width
Returns:
width of tree house
getLength
Gives tree house length
Returns:
length of tree house
getHeight
Gives height of tree house above ground
Returns:
height of tree house
getTree
Gives tree type
Returns:
the kind of tree
area
Gives tree house area
Returns:
area of tree house
dangerous
Determines if tree house is dangerous - 10 or more feet high
Returns:
true if height is ten feet or higher
Field Summary private int heightAboveGroundTree house height above ground private int length
Tree house length private java.lang.String treeKind
Tree house kind of tree, e.g. oak private int width
Tree house width
Explanation / Answer
HI, Please find my implementation.
Please let me know in case of any issue.
public class TreeHouse {
private int heightAboveGround;
private int length;
private String treeKind;
private int width;
// constructor
public TreeHouse(int theWidth, int theLength, int theHeight, java.lang.String tree){
heightAboveGround = theHeight;
length = theLength;
width = theWidth;
treeKind =tree;
}
public int getWidth(){
return width;
}
public int getLength(){
return length;
}
public int getHeight(){
return heightAboveGround;
}
public java.lang.String getTree(){
return treeKind;
}
public int area(){
return length*width*heightAboveGround;
}
public boolean dangerous(){
if(heightAboveGround >= 10)
return true;
else
return false;
}
public static void main(String[] args) {
TreeHouse danasHouse = new TreeHouse(23, 12, 13, "PKKK");
System.out.println("Is house dangerous ? "+danasHouse.dangerous());
}
}
/*
Sample run:
Is house dangerous ? true
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.