定义一个圆类Circle,描述圆对象。圆有一个属性radius表示半径,至少有一个带参构造方法给半
发布网友
发布时间:2022-05-10 21:23
我来回答
共1个回答
热心网友
时间:2023-11-02 02:13
class Circle {
private double radius;
public Circle() {
this(1);
}
public Circle(double r) {
radius = r;
}
public double area() {
return Math.PI * radius * radius;
}
public double circumference() {
return 2 * Math.PI * radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public String toString() {
return "Circle with a radius of " + radius;
}
}