/** * 三角形(已知底与高):面积 = 底 * 高 / 2 */ public class Triangle extends Shape { private final double base; private final double height; public Triangle(double base, double height) { if (base <= 0 || height <= 0) { throw new IllegalArgumentException("底和高必须为正数"); } this.base = base; this.height = height; } public double getBase() { return base; } public double getHeight() { return height; } @Override public double getArea() { return base * height / 2.0; } }