SHARE
TWEET

Untitled

a guest Jul 17th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class CircleWithPrivateDataFields {
  2.   /** The radius of the circle */
  3.   private double radius = 1;
  4.  
  5.   /** The number of the objects created */
  6.   private static int numberOfObjects = 0;
  7.  
  8.   /** Construct a circle with radius 1 */
  9.   public CircleWithPrivateDataFields() {
  10.     numberOfObjects++;
  11.   }
  12.  
  13.   /** Construct a circle with a specified radius */
  14.   public CircleWithPrivateDataFields(double newRadius) {
  15.     radius = newRadius;
  16.     numberOfObjects++;
  17.   }
  18.  
  19.   /** Return radius */
  20.   public double getRadius() {
  21.     return radius;
  22.   }
  23.  
  24.   /** Set a new radius */
  25.   public void setRadius(double newRadius) {
  26.     radius = (newRadius >= 0) ? newRadius : 0;
  27.   }
  28.  
  29.   /** Return numberOfObjects */
  30.   public static int getNumberOfObjects() {
  31.     return numberOfObjects;
  32.   }
  33.  
  34.   /** Return the area of this circle */
  35.   public double getArea() {
  36.     return radius * radius * Math.PI;
  37.   }
  38. }
RAW Paste Data
Top