1  public class SimpleCircle {
  2    /** Main method */
  3    public static void main(String[] args) {
  4      // Create a circle with radius 1
  5      SimpleCircle circle1 = new SimpleCircle();
  6      System.out.println("The area of the circle of radius "
  7        + circle1.radius + " is " + circle1.getArea());
  8    
  9      // Create a circle with radius 25
 10      SimpleCircle circle2 = new SimpleCircle(25);
 11      System.out.println("The area of the circle of radius "
 12        + circle2.radius + " is " + circle2.getArea());
 13    
 14      // Create a circle with radius 125
 15      SimpleCircle circle3 = new SimpleCircle(125);
 16      System.out.println("The area of the circle of radius "
 17        + circle3.radius + " is " + circle3.getArea());
 18    
 19      // Modify circle radius
 20      circle2.radius = 100;
 21      System.out.println("The area of the circle of radius "
 22        + circle2.radius + " is " + circle2.getArea());
 23    }
 24    
 25    double radius; 
 26   
 27    /** Construct a circle with radius 1 */
 28    SimpleCircle() {
 29      radius = 1;
 30    }
 31    
 32    /** Construct a circle with a specified radius */
 33    SimpleCircle(double newRadius) {
 34      radius = newRadius;
 35    }
 36    
 37    /** Return the area of this circle */
 38    double getArea() {
 39      return radius * radius * Math.PI;
 40    }
 41    
 42    /** Return the perimeter of this circle */
 43    double getPerimeter() {
 44      return 2 * radius * Math.PI;
 45    }
 46    
 47    /** Set a new radius for this circle */
 48    void setRadius(double newRadius) {
 49      radius = newRadius;
 50    }
 51  }