You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
758 B

/**
* 测试类:验证图形面积计算器的功能
*/
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);
}
}