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.
 
 

21 lines
762 B

public class Main {
public static void main(String[] args) {
// 创建图形对象
Shape circle = new Circle(5.0);
Shape rectangle = new Rectangle(4.0, 6.0);
Shape triangle = new Triangle(3.0, 8.0);
// 存入数组,统一处理(多态)
Shape[] shapes = { circle, rectangle, triangle };
System.out.println("===== 图形面积计算器 =====");
for (Shape s : shapes) {
ShapeUtil.printArea(s);
}
System.out.println();
Shape largest = ShapeUtil.findLargest(shapes);
System.out.println("面积最大的图形是:" + largest.getName()
+ "(面积 = " + String.format("%.2f", largest.getArea()) + ")");
}
}