class Circle
{
private double r;
final double PI=3.14159;
public Circle(double r)
{
this.r=r;
}
public Circle()
{
this.r=1;
}
public double area()
{
return PI*r*r;
}
public double circunference()
{
return 2*PI*r;
}
public String toString()
{
return "Circle with radius "+this.r;
}
public void setRadius(double r)
{
this.r=r;
}
public double getRadius()
{
return this.r;
}
}
public class JLab0401B
{
public static void main(String[] arg)
{
Circle myCircle1=new Circle(3.2);
Circle myCircle2=new Circle();
System.out.println("myCircle1面积:"+myCircle1.area());
System.out.println("myCircle2面积:"+myCircle2.area());
System.out.println("myCircle1周长:"+myCircle1.circunference());
System.out.println("myCircle2周长:"+myCircle2.circunference());
System.out.println("myCircle1情况:"+myCircle1.toString());
System.out.println("myCircle2情况:"+myCircle2.toString());
myCircle1.setRadius(5.4);
myCircle2.setRadius(3.2);
System.out.println("myCircle1的半径:"+myCircle1.getRadius());
System.out.println("myCircle2的半径:"+myCircle2.getRadius());
}
}
[此贴子已经被作者于2005-7-19 11:08:40编辑过]