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

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

ID: 3543378 • Letter: C

Question

Create a class name Circle with fields named radius, diameter, and area. Include a constuctor that sets the radius to 1 and calculates

the other two values. Also include methods named setRadius() and getRadius(). The setRadius() method not only sets the radius vut also calculates the other two values. (The diameter of the circle is twice the radius, and the area of the 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

Explanation / Answer

public class Circle {

double radius;

double diameter;

double area;

public Circle(){

radius = 1.0;

diameter = 2*radius;

area = Math.PI * radius * radius;

}

public void setRadius(double r){

radius = r;

diameter = 2*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