Thanks in advance. Modify 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.)
Thanks in advance.
Modify 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.)
class Circle {
private double radius;
private double area;
private double diameter;
Circle() {
}
public void setRadius(double r) {
}
public double getRadius() {
}
private void computeDiameter() {
}
private void computeArea() {
}
public double getDiameter() {
}
public double getArea() {
}
}
class TestCircle {
public static void main (String args[]) {
Circle a = new Circle();
Circle b = new Circle();
Circle c = new Circle();
a.setRadius(1.5);
b.setRadius(1500.50);
System.out.println("The area of a is " +
a.getArea());
System.out.println("The diameter of a is " +
a.getDiameter());
System.out.println("The area of b is " +
b.getArea());
System.out.println("The diameter of b is " +
b.getDiameter());
System.out.println("The area of c is " +
c.getArea());
System.out.println("The diameter of c is " +
c.getDiameter());
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images