3.封裝一類圓形對象Circle,該類對象具有半徑的屬性,具有初始化圓的功能、修改半徑的功能、求周長的功能、求面積的功能。package hu;
public class TestCircle {
private double r;
TestCircle(double r){
this.r = r;
}
TestCircle(){
this.r = 1;
}
public void set_r(double r){
this.r = r;
}
public double get_Perimeter(){
double s=2*Math.PI*r;
return s;
}
public double get_Area(){
double s1;
s1=(Math.PI)*r*r;
return s1;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
TestCircle t = new TestCircle(3);
t.get_Area();
t.get_Perimeter();
double x1,x2;
x1=t.get_Area();
x2=t.get_Perimeter();
System.out.println(x1+" "+x2);
}
}