Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 23rd, 2012  |  syntax: Java  |  size: 1.27 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  * Circle class.
  3.  */
  4. public class Circle {
  5.         private static final double PI = 3.14;
  6.         private double radius;
  7.        
  8.         /**
  9.          * constructor
  10.          * pre: none
  11.          * post: A Circle object created. Radius initialized to 1.
  12.          */
  13.         public Circle() {
  14.                 radius = 1;     //default radius
  15.         }
  16.        
  17.        
  18.         /**
  19.          * Changes the radius of the circle.
  20.          * pre: none
  21.          * post: Radius has been changed.
  22.          */
  23.         public void setRadius(double newRadius) {
  24.                 radius = newRadius;
  25.         }
  26.        
  27.        
  28.         /**
  29.          * Calculates the area of the circle.
  30.          * pre: none
  31.          * post: The area of the circle has been returned.
  32.          */
  33.         public double area() {
  34.                 double circleArea;
  35.                
  36.                 circleArea = PI * radius * radius;
  37.                 return(circleArea);
  38.         }
  39.        
  40.        
  41.         /**
  42.          * Returns the radius of the circle.
  43.          * pre: none
  44.          * post: The radius of the circle has been returned.
  45.          */
  46.         public double getRadius() {
  47.                 return(radius);
  48.         }
  49.         public static double circumference(int getRadius, double PI) {
  50.                 double circumference;
  51.                 circumference = 2 * PI * getRadius;
  52.                 return(circumference);
  53.         }
  54.         public static void main (String[] args) {
  55.                 Circle spot = new Circle();
  56.                
  57.                 spot.setRadius(3);
  58.                 System.out.println("Circle radius: " + spot.getRadius());
  59.                 System.out.println("Circle circumference: " + spot.circumference(getRadius, PI));
  60.         }
  61. }