Для расчета площади и периметра каждой из фигур, нужно знать формулы для каждой из них. Ниже приведены формулы для каждой из фигур:
.
Ниже приведен Java код для расчета площади и периметра каждой из фигур:
public abstract class Figure {
protected double[] sides;
public Figure(double[] sides) {
this.sides = sides;
}
public abstract double getArea();
public abstract double getPerimeter();
}
public class Triangle extends Figure {
public Triangle(double[] sides) {
super(sides);
}
@Override
public double getArea() {
double b = sides[0];
double h = sides[1];
return 0.5 * b * h;
}
@Override
public double getPerimeter() {
double a = sides[0];
double b = sides[1];
double c = sides[2];
return a + b + c;
}
}
public class IsoscelesTriangle extends Triangle {
public IsoscelesTriangle(double[] sides) {
super(sides);
}
@Override
public double getPerimeter() {
double a = sides[0];
double b = sides[1];
return 2 * a + b;
}
}
public class EquilateralTriangle extends Triangle {
public EquilateralTriangle(double[] sides) {
super(sides);
}
@Override
public double getArea() {
double a = sides[0];
return Math.sqrt(3) / 4 * a * a;
}
@Override
public double getPerimeter() {
double a = sides[0];
return 3 * a;
}
}
public class RightTriangle extends Triangle {
public RightTriangle(double[] sides) {
super(sides);
}
@Override
public double getArea() {
double a = sides[0];
double b = sides[1];
return 0.5 * a * b;
}
@Override
public double getPerimeter() {
double a = sides[0];
double b = sides[1];
double c = Math.sqrt(a * a + b * b);
return a + b + c;
}
}
public abstract class Quadrilateral extends Figure {
public Quadrilateral(double[] sides) {
super(sides);
}
public abstract double getDiagonal();
public abstract double getAngle();
}
public class ConvexQuadrilateral extends Quadrilateral {
public ConvexQuadrilateral(double[] sides) {
super(sides);
}
@Override
public double getArea() {
// TODO: implement formula for area of convex quadrilateral
return 0;
}
@Override
public double getPerimeter() {
double a = sides[0];
double b = sides[1];
double c = sides[2];
double d = sides[3