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.
27 lines
1.3 KiB
27 lines
1.3 KiB
package tiaozhanti;
|
|
|
|
import jichuti.Circle;
|
|
|
|
public class ChallengeTest {
|
|
public static void main(String[] args) {
|
|
// 1. 测试图形转换
|
|
ShapeConverter converter = new BasicShapeConverter();
|
|
Circle circle = new Circle("yellow", 2); // 面积≈12.57
|
|
Oval oval = (Oval) converter.convert(circle, Oval.class); // 圆形→椭圆形
|
|
Circle convertedCircle = (Circle) converter.convert(oval, Circle.class); // 椭圆形→圆形
|
|
|
|
// 2. 测试复合图形
|
|
CompositeShape composite = new CompositeShape("mixed");
|
|
composite.addShape(new Square()); // 面积9
|
|
composite.addShape(new Circle("blue", 2)); // 面积≈12.57
|
|
composite.addShape(new Oval("green", 2, 1)); // 面积≈6.28
|
|
|
|
// 输出结果
|
|
System.out.println("\n=== 挑战题测试结果 ===");
|
|
System.out.println("圆形转椭圆形面积:" + String.format("%.2f", oval.getArea()));
|
|
System.out.println("椭圆形转回圆形面积:" + String.format("%.2f", convertedCircle.getArea()));
|
|
|
|
System.out.println("\n复合图形包含 " + composite.getChildren().size() + " 个子图形");
|
|
System.out.println("复合图形总面积:" + String.format("%.2f", composite.getArea()));
|
|
}
|
|
} |