interface Shape {
double area();
}
class Circle implements Shape {
private double radius;
Circle(double radius) {
this.radius = radius;
}
@Override
public double area() {
return Math.PI * radius * radius;
}
}
class Rectangle implements Shape {
private double length;
private double width;
Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
@Override
public double area() {
return length * width;
}
}
public class ShapeAreaCalculator {
public static void main(String[] args) {
Shape circle = new Circle(5);
Shape rectangle = new Rectangle(4, 6);
System.out.println("圓形面積: " + circle.area());
System.out.println("矩形面積: " + rectangle.area());
}
}interface Shape { double area(); }
class Circle implements Shape { private double radius;


Circle(double radius) {
this.radius = radius;
}
@Override
public double area() {
return Math.PI * radius * radius;
}


}
class Rectangle implements Shape { private double length; private double width;


Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
@Override
public double area() {
return length * width;
}


}
public class ShapeAreaCalculator { public static void main(String[] args) { Shape circle = new Circle(5); Shape rectangle = new Rectangle(4, 6);


System.out.println("圓形面積: " + circle.area());
System.out.println("矩形面積: " + rectangle.area());
}


}