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
553 B

public class ShapeUtil {
/**
* 统一打印任意图形的面积(多态调用)
*/
public static void printArea(Shape shape) {
System.out.printf("%s 的面积为:%.2f%n", shape.getName(), shape.getArea());
}
/**
* 找出面积最大的图形
*/
public static Shape findLargest(Shape[] shapes) {
Shape largest = shapes[0];
for (Shape s : shapes) {
if (s.getArea() > largest.getArea()) {
largest = s;
}
}
return largest;
}
}