Ask Question
24 June, 03:57

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 setRadius () and getRadius (). The setRadius () method not only sets the radius, but 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.

+5
Answers (1)
  1. 24 June, 04:21
    0
    The code for this class is shown in the explanation section

    Explanation:

    public class Circle {

    private double radius;

    private double diameter;

    private double area;

    public Circle (double radius, double diameter, double area) {

    this. radius = 1;

    this. diameter = diameter;

    this. area = area;

    }

    public void setRadius (double radius) {

    this. radius = radius;

    diameter = radius*2;

    area = Math. PI * (radius*radius);

    }

    public double getRadius () {

    return radius;

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers