I got the first part correct but how do I put the get height into the second part? Like would I just repeat everything the base did.. like "private double height" " public void setHeight " etc...
The design is this:
RightTriangle
variables: base, height
methods:
setBase - changes the base
setHeight - changes the height
getBase - returns the base
getHeight - returns the height
area - returns the rea of the triangle(1/2bh)
The output is suppose to be:
The base of the right triangle is 4.0
the height of the right triangle is 5.0
The area of the right triable is 10.0
My code so far is:
public class RightTriangle {
public static void main(String[] args) {
Triangle shape = new Triangle();
shape.setBase(4.0);
shape.setHeight(5.0);
System.out.println("The base of the right triangle is " + shape.getBase());
System.out.println("The height of the right triangle is " + shape.getHeight());
System.out.println("The area of the right triangle is " + shape.area());
}
}
The class code is:
public class Triangle {
private double base;
public Triangle() {
base = 1;
}
public void setBase(double newBase) {
base = newBase;
}
public double area() {
double triangleArea;
triangleArea = 1/2 * base * height;
return(triangleArea);
}
public double getBase() {
return(base);
}
}