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.
23 lines
467 B
23 lines
467 B
/**
|
|
* 圆:面积 = π * r²
|
|
*/
|
|
public class Circle extends Shape {
|
|
|
|
private final double radius;
|
|
|
|
public Circle(double radius) {
|
|
if (radius <= 0) {
|
|
throw new IllegalArgumentException("半径必须为正数");
|
|
}
|
|
this.radius = radius;
|
|
}
|
|
|
|
public double getRadius() {
|
|
return radius;
|
|
}
|
|
|
|
@Override
|
|
public double getArea() {
|
|
return Math.PI * radius * radius;
|
|
}
|
|
}
|
|
|