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.

29 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package jichuti;
import java.util.ArrayList;
import java.util.List;
public class BasicTest {
public static void main(String[] args) {
// 创建图形列表
List<Shape> 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<Shape> 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())
);
}
}
}