BenitoDannes

PBO-4.1-1 Circle

Mar 20th, 2017
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1.  
  2. /**
  3.  * Program untuk mencari luas lingkaran
  4.  *
  5.  * Benito Dannes
  6.  */
  7.  
  8. public class Circle
  9. {
  10.     public static final double DEFAULT_RADIUS = 8.8;
  11.     public static final String DEFAULT_COLOR = "red";
  12.    
  13.     private double radius;
  14.     private String color;
  15.    
  16.     public Circle()
  17.     {
  18.         radius = DEFAULT_RADIUS;
  19.         color = DEFAULT_COLOR;
  20.     }
  21.    
  22.     public Circle (double radius)
  23.     {
  24.         this.radius = radius;
  25.         color = DEFAULT_COLOR;
  26.     }
  27.    
  28.     public Circle (double radius, String color)
  29.     {
  30.         this.radius = radius;
  31.         this.color = color;
  32.     }
  33.  
  34.     public double getRadius()
  35.     {
  36.         return radius;
  37.     }
  38.    
  39.     public void setRadius (double radius)
  40.     {
  41.         this.radius = radius;
  42.     }
  43.    
  44.     public String getColor()
  45.     {
  46.         return color;
  47.     }
  48.    
  49.     public void setColor (String color)
  50.     {
  51.         this.color = color;
  52.     }
  53.    
  54.     public double getDiameter()
  55.     {
  56.         return radius * 2;
  57.     }
  58.    
  59.     public double getArea()
  60.     {
  61.         return Math.PI * Math.pow (radius, 2);
  62.     }
  63.    
  64.     public double getCircumference()
  65.     {
  66.         return Math.PI * getDiameter();
  67.     }
  68.    
  69.     public String toString()
  70.     {
  71.         return "Circle with radius = " + radius + " and color is " + color;
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment