therrontelford

Circle

Sep 15th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. /*
  2.  * Telford
  3.  * September 14, 2017
  4.  * Circle class
  5.  */
  6. public class Circle {
  7.  
  8.     private double radius;
  9.    
  10.     public Circle() {
  11.         radius =1;
  12.     }
  13.    
  14.     public Circle(double r) {
  15.         radius = r;
  16.     }
  17.    
  18.     public double getArea() {
  19.         return radius * radius * Math.PI;
  20.     }
  21.    
  22.     public double getPerimeter() {
  23.         return 2 * Math.PI * radius;
  24.     }
  25.  
  26.     public String toString(){
  27.         return "The area and perimeter of this circle is " + getArea() + " " + getPerimeter();
  28.     }
  29.    
  30.     public void setRadius(double newRadius) {
  31.         radius = newRadius;
  32.        
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment