Create a Right Triangle class given the following design:
Class RightTriangle
Variables:
base, height
Methods:
setBase – changes the base. Requires one parameter for the base
setHeight – changes the height. Requires one parameter for the height
getBase – returns the triangle base
getHeight – returns the triangle height
area – returns the area of the triangle (A = 1
/2 * b * h) given the current base and height.
Write an appropriate class / application that will test the RightTriangle class.
1
Expert's answer
2016-03-18T15:48:04-0400
package righttriangle;
public class Test { /** * @param args the command line arguments */ public static void main(String[] args) { RightTriangle triangle = new RightTriangle(); triangle.setBase(4.6); triangle.setHeight(8.1); System.out.println("Area: " + triangle.area()); } } //////////////////////////////////////////////////////////////////////////////////////////// package righttriangle;
public class RightTriangle {
private double base; private double height;
public void setBase(double base) { this.base = base; }
public void setHeight(double height) { this.height = height; }
Comments
Leave a comment