Advertisement
Anthei

Circle

Oct 22nd, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. /* Eva Goins
  2.  * Chapter 6
  3.  * Description: The class Circle has the fields radius (double)
  4.  *      and PI (final double), the constructors Circle that allows
  5.  *      immediate input of the radius, and the no args constructor.
  6.  *      The class also uses methods setRadius to set the radius
  7.  *      should it be user-input, getRadius to obtain the radius
  8.  *      currently set, getArea to calculate the area, getDiameter
  9.  *      to calculate the diameter, and getCircumference to calculate
  10.  *      the circumference. All non-constructor methods return a
  11.  *      double value.
  12.  */
  13.  
  14.  public class Circle
  15.  {
  16.     double radius;
  17.     final double PI = 3.14159;
  18.    
  19.     public Circle(double rad)
  20.     {
  21.         radius = rad;
  22.     }
  23.    
  24.     public Circle()
  25.     {
  26.         radius = 0.0;
  27.     }
  28.    
  29.     public void setRadius(double rad)
  30.     {
  31.         radius = rad;
  32.     }
  33.    
  34.     public double getRadius()
  35.     {
  36.         return radius;
  37.     }
  38.    
  39.     public double getArea()
  40.     {
  41.         return PI * radius * radius;
  42.     }
  43.    
  44.     public double getDiameter()
  45.     {
  46.         return radius * 2;
  47.     }
  48.    
  49.     public double getCircumference()
  50.     {
  51.         return 2 * PI * radius;
  52.     }
  53.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement