public class RecordPatternDemo {
    sealed interface Shape permits Circle, Rect {}
    record Circle(double radius) implements Shape {}
    record Rect(double width, double height) implements Shape {}

    static double area(Shape shape) {
        return switch (shape) {
            case Circle(var r) -> Math.PI * r * r;
            case Rect(var w, var h) -> w * h;
        };
    }

    public static void main(String[] args) {
        System.out.printf("circle=%.2f%n", area(new Circle(1)));
        System.out.printf("rect=%.2f%n", area(new Rect(2, 3)));
    }
}
