• Sign Up
• Login
• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Dec 23rd, 2012 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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. }
RAW Paste Data
Top