package joker; public class Test_1106 { public static void main(String[] args) { // TODO Auto-generated method stub TestDemo circle1 = new TestDemo(); double area=circle1.getArea(); System.out.println(area); TestDemo circle2=new TestDemo(10); System.out.println(circle2.getArea()); System.out.println(circle1.getPerimeter()); System.out.println(circle2.getPerimeter()); double ridius=10; double areaCircle=Math.PI*ridius*ridius; System.out.println(areaCircle); circle2.setRadius(5); System.out.println(circle2.getArea()); } }
package joker; public class TestDemo { private double radius; public TestDemo(double radius) { this.radius = radius; } public TestDemo() { this.radius = 1.0; } public double getArea() { return Math.PI * radius * radius; } public double getPerimeter() { return 2 * Math.PI * radius; } public void setRadius(double newRadius) { this.radius = newRadius; } }