package jichuti; import java.util.ArrayList; import java.util.List; public class BasicTest { public static void main(String[] args) { // 创建图形列表 List shapes = new ArrayList<>(); shapes.add(new Square("red", 5)); // 红色正方形(面积25) shapes.add(new Square("blue", 3)); // 蓝色正方形(面积9) shapes.add(new Circle("red", 2)); // 红色圆形(面积≈12.57) shapes.add(new Circle("green", 4)); // 绿色圆形(面积≈50.27) // 测试颜色过滤 ColorFilter filter = new ColorFilter(); List redShapes = filter.filterByColor(shapes, "red"); // 输出结果 System.out.println("=== 基础题测试结果 ==="); System.out.println("红色图形共 " + redShapes.size() + " 个:"); for (Shape shape : redShapes) { System.out.println( shape.getClass().getSimpleName() + " - 面积:" + String.format("%.2f", shape.getArea()) ); } } }