...

/

Solution Review: Calculating the Area

Solution Review: Calculating the Area

In this review, solution of the challenge 'Calculating the Area' from the previous lesson is provided.

Solution: Did you find the ‘right’ area? #

Press + to interact
class rightAngleTriangle {
//Define the member variables, constructor and
// relevant area method
private double length;
private double height;
public rightAngleTriangle(int l, int h) {
length = l;
height = h;
}
public double area() {
return (length * height / 2.0);
}
}
class challenge_one {
public static double test(rightAngleTriangle rt) {
return rt.area();
}
public static void main( String args[] ) {
rightAngleTriangle one= new rightAngleTriangle(3,5);
System.out.println("Area of right Angle traingle:" + test(one));
}
}

Understanding the code

...