/** * 测试类:验证图形面积计算器的功能 */ public class TestShape { public static void main(String[] args) { // 1. 创建圆形(半径5) Shape circle = new Circle(5); // 2. 创建矩形(长4,宽3) Shape rectangle = new Rectangle(4, 3); // 3. 创建三角形(底6,高4) Shape triangle = new Triangle(6, 4); // 调用工具类打印面积(统一处理所有图形) System.out.println("===== 圆形面积 ====="); ShapeUtil.printArea(circle); System.out.println("===== 矩形面积 ====="); ShapeUtil.printArea(rectangle); System.out.println("===== 三角形面积 ====="); ShapeUtil.printArea(triangle); } }