64 679
Assignments Done
99,2%
Successfully Done
In September 2018

Answer to Question #58407 in Java | JSP | JSF for Nic

Question #58407
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.
Expert's answer
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;
}

public double getBase() {
return base;
}

public double getHeight() {
return height;
}

public double area(){
return base*height/2;

}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions