Reference no: EM131878765
Please help with the following call using a testcircle.java ? May have to change the original...lost here
a. a class named Circle with fields named radius, diameter, and area. Including a constructor that sets the radius to 1 and calculates the other two values. Also including methods named setRadius()and getRadius(). The setRadius() method not only sets the radius but 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. Using the Math class PI constant for this calculation.) class as Circle.java.
b. 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. Displaying all the values for all the Circle objects. Save the application as TestCircle.java.
public class Circle {
public static void main(String[] args);{
public double radius;
public double diameter;
public double area;
public double circum;
public Circle() {
radius = 1.0;
diameter = 2*radius;
area = Math.PI * radius * radius;
circum = 2 * Math.PI * radius;
}
public Circle(double r) {
radius = r;
diameter = 2*radius;
area = Math.PI * radius * radius;
circum = 2 * Math.PI * radius;
}
public void setRadius(double r) {
radius = r;
diameter = 2*radius;
area = Math.PI * radius * radius;
circum = 2 * Math.PI * radius;
}
public double getRadius() {
return radius;
}
public double getArea() {
return area;
}
public double getDiameter() {
return diameter;
}
public double getCircumference() {
return circum;
}
public String toString(){
return "Radius = " + radius +
"nArea = " + area +
"nCircumference = " + circum;
}
}