Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 You are to design a base clase that would represent a Circle. Given the follow

ID: 3558911 • Letter: 1

Question

1 You are to design a base clase that would represent a Circle. Given the following UML representation of a class write the java code for the class: (20pts.) Circle # radius Double + set Radius(double): void // Sets radius to the given value + print(): void // prints the circle info: radius, area and circumference labeled and one per line + calculateCircumference() : double // Calculates and returns circumference 2*PI*r +calculateArea():double // calculates and return area PI * r * r +getRadius(): double // Returns radius +toString(): String +equa(Circle): Boolean +Circle (double)

Explanation / Answer


public class Circle
{
   private double radius;
  
   public void setRadius(double r)
   {
       radius = r;
   }
  
   public double calculateCircumference()
   {
       return 2*Math.PI*radius;
   }
  
   public double calculateArea()
   {
       return Math.PI*radius*radius;
   }
  
   public double getRadius()
   {
       return radius;
   }
  
   public void Print()
   {
       System.out.println("Radius = " + radius);
       System.out.println("Area = " + calculateArea());
       System.out.println("Circumference = " + calculateCircumference());
   }
  
   public String toString()
   {
       return Double.toString(radius);
   }
  
   public boolean equal(Circle circle)
   {
       return (radius == circle.getRadius());
   }
  
   public Circle()
   {
       radius = 0;
   }
  
   public Circle(double r)
   {
       radius = r;
   }

}