package myprojects.Interface;
public class Triangle implements Shape {
// Sides of the triangle
private double opp;
private double adj;
public Triangle (double opp, double adj) {
this.opp = opp;
this.adj = adj;
}
public double area() {
// the area of a right angled triangle
// is half the opposite * the adjacent
return 0.5 * opp * adj;
}
public double perimeter() {
// calculate the area of the RH triangle
// using Pythagoras's theorem...
return (opp + adj + Math.sqrt(opp*opp+adj*adj));
}
} |