SHARE
TWEET

2.10.6: Circle Area

OGKP Nov 19th, 2019 136 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class CircleTester
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         Circle cup = new Circle(5);
  6.         System.out.println("Area of a circle with radius 5: " + cup.getArea());  
  7.         System.out.println("Circumference of a circle with radius 5: " + cup.getCircumference());  
  8.  
  9.         Circle hat = new Circle(12);
  10.         System.out.println("\nArea of a circle with radius 12: " + hat.getArea());  
  11.         System.out.println("Circumference of a circle with radius 12: " + hat.getCircumference());  
  12.  
  13.     }
  14. }
  15.  
  16.  
  17.  
  18.  
  19.  
  20. public class Circle
  21. {
  22.     private double radius;
  23.    
  24.     public Circle(double theRadius)
  25.     {
  26.         radius = theRadius;
  27.     }
  28.  
  29.     // Implement getArea using
  30.     // Math.PI and
  31.     // Math.pow
  32.     // Area = pi * r^2
  33.     public double getArea()
  34.     {
  35.       Double Area = Math.PI * Math.pow(radius, 2);
  36.       return Area;  
  37.     }
  38.    
  39.     // Implement getCircumference using
  40.     // Math.PI
  41.     // Circumference = 2 * PI * r
  42.     public double getCircumference()
  43.     {
  44.     double Circumference = 2 * Math.PI * radius;
  45.        return Circumference;
  46.     }
  47.    
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top