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.

20 lines
775 B

/**
* 测试类,验证图形面积计算器的功能
*/
public class Main {
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);
// 4. 通过工具类统一打印面积(多态效果)
System.out.println("=== 圆形面积 ===");
ShapeUtil.printArea(circle);
System.out.println("\n=== 矩形面积 ===");
ShapeUtil.printArea(rectangle);
System.out.println("\n=== 三角形面积 ===");
ShapeUtil.printArea(triangle);
}
}