fosterbl

Circle.java

Dec 17th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. public class Circle{
  2.   //Field
  3.   private int radius;
  4.  
  5.   //Specified (parameterized) Constructor
  6.   public Circle( int r ){
  7.     radius = r;
  8.   }
  9.  
  10.   //Accessor
  11.   public int getRadius(){
  12.     return radius;
  13.   }
  14.  
  15.   //Mutator
  16.   public void setRadius( int r ){
  17.     radius = r;
  18.   }
  19.  
  20.   //area - calculates and returns the area of the circle
  21.   public double area(){
  22.     return Math.PI * Math.pow( radius, 2 );
  23.   }
  24.  
  25.   //circumference - calculates and returns the circumference of the circle
  26.   public double circumference(){
  27.     return 2 * Math.PI * radius;
  28.   }
  29.  
  30.   //toString - returns a textually representative String of the Circle object
  31.   public String toString(){
  32.     return "This circle has a radius of " + radius;
  33.   }
  34.  
  35.   //equals - returns true if two circle have the exact same radius
  36.   public boolean equals( Circle other ){
  37.     return this.getRadius() == other.getRadius();
  38.   }
  39. }
Add Comment
Please, Sign In to add comment