Newer
Older
commitconf24 / snippets / Shape.java
@Antonio Muñoz Antonio Muñoz on 8 Feb 2024 514 bytes add snippets
package snippets;

public sealed interface Shape {

    default double area() {
        var area = switch (this) {
            case Square(var side) -> side * side;
            case Rectangle(var weight, var height) -> weight * height;
            case Circle(var radious) -> Math.PI * Math.pow(radious, 2);
        };
        return area;
    }

    record Square(int side) implements Shape {}
    record Rectangle(int weight, int height) implements Shape {}
    record Circle(int radious) implements Shape {}

}