: Write the Class for Circle. Read the following code and create the attributes, method, constructors of class according so that it produces the result as given below.
Code:
publicclass
Main {
publicstaticvoidmain(String[] args) {
System.
out
.println("Value of PI: "+ Circle.PI);
System.
out
.println("Square of 2.0 is: " + Circle.square(2.0));
Circle c1 =
newCircle(3.4);
Circle c2 =
newCircle(2.9);
c1.display();
c2.display();
System.
out
.println(c1.compare(c2));
System.
out
.println(c2.compare(c1));
c1 = c2.getCopy();
System.
out
.println(c1.compare(c2));
System.
out
.println(c2.compare(c1));
c1.set(5.0);
System.
out
.println(c1.getRadius());
System.
out
.println(c1.getDiameter());
System.
out
.println(c1.getCircumference());
System.
out
.println(c1.getArea());
Circle c3 = c2.getClone();
c3.set(c1.getDiameter());
c2.display();
c3.set(c1);
c1.display();
c2.display();
c3.display();
}
}
Output:
Value of PI: 3.14
Square of 2.0 is: 4.0
Radius: 3.4, Diameter: 6.8, Circumference: 21.352, Area: 36.2984
Radius: 2.9, Diameter: 5.8, Circumference: 18.212, Area: 26.407400000000003
1
-1
0
0
5.0
10.0
31.400000000000002
78.5
Radius: 10.0, Diameter: 20.0, Circumference: 62.800000000000004, Area: 314.0
Radius: 5.0, Diameter: 10.0, Circumference: 31.400000000000002, Area: 78.5
Radius: 5.0, Diameter: 10.0, Circumference: 31.400000000000002, Area: 78.5
Radius: 5.0, Diameter: 10.0, Circumference: 31.400000000000002, Area: 78.5