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

Create a class named Circle with fields named radius, diameter, and area. Includ

ID: 673868 • Letter: C

Question

Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named set Radius () and getRadius(). The setRadius() method not only sets the radius, it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant for this calculation.) Save the class as Circle.java. Create a class named TestCircle whose main() method declares several Circle objects. Using the setRadius() method, assign one Circle a small radius value, and assign another a larger radius value. Do not assign a value to the radius of the third circle; instead, retain the value assigned at construction. Display all the values for all the Circle objects. Save the application as TestCircle.java. Write a Java application that uses the Math class to determine the answers for each of the following:

Explanation / Answer

class Circle{
   double radius, diameter, area;
   public void setRadius(double rad){
       radius = rad;
       diameter = 2*Math.PI*radius;
       area = Math.PI*radius*radius;
   }
   public double getRadius(){
       return radius;
   }  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote