12

 1 public class L1106 {
 2   
 3       public static void main(String[] args) {
 4           // TODO Auto-generated method stub
 5           TestDemo circle1 = new TestDemo();
 6           double area=circle1.getArea();
 7           System.out.println(area);
 8           TestDemo circle2=new TestDemo(10);
 9           System.out.println(circle2.getArea());
10         System.out.println(circle1.getPerimeter());
11          System.out.println(circle2.getPerimeter());
12          double ridius=10;
13          double areaCircle=Math.PI*ridius*ridius;
14          System.out.println(areaCircle);
15          circle2.setRadius(5);
16          System.out.println(circle2.getArea());
17      }
18  
19  }
20 
21 
22 
23 
24 public class TestDemo {
25   
26   private double radius;
27       
28       public TestDemo(double radius) {
29           this.radius = radius;
30       }
31       public TestDemo() {
32           this.radius = 1.0;
33      }
34      public double getArea() {
35          return Math.PI * radius * radius;
36      }
37      public double getPerimeter() {
38          return 2 * Math.PI * radius;
39      }
40      public void setRadius(double newRadius) {
41          this.radius = newRadius;
42      }
43  }

 

posted @ 2017-12-18 14:26  mxl-1  阅读(114)  评论(0编辑  收藏  举报