Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Circle class.
- */
- public class Circle {
- private static final double PI = 3.14;
- private double radius;
- /**
- * constructor
- * pre: none
- * post: A Circle object created. Radius initialized to 1.
- */
- public Circle() {
- radius = 1; //default radius
- }
- /**
- * Changes the radius of the circle.
- * pre: none
- * post: Radius has been changed.
- */
- public void setRadius(double newRadius) {
- radius = newRadius;
- }
- /**
- * Calculates the area of the circle.
- * pre: none
- * post: The area of the circle has been returned.
- */
- public double area() {
- double circleArea;
- circleArea = PI * radius * radius;
- return(circleArea);
- }
- /**
- * Returns the radius of the circle.
- * pre: none
- * post: The radius of the circle has been returned.
- */
- public double getRadius() {
- return(radius);
- }
- public static double circumference(int getRadius, double PI) {
- double circumference;
- circumference = 2 * PI * getRadius;
- return(circumference);
- }
- public static void main (String[] args) {
- Circle spot = new Circle();
- spot.setRadius(3);
- System.out.println("Circle radius: " + spot.getRadius());
- System.out.println("Circle circumference: " + spot.circumference(getRadius, PI));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement