Answer:
Check the explanation
Explanation:
Circle.java
public class Circle {
private double radius;
public Circle(double r) {
radius = r;
}
public double getArea() {
return Math.PI * radius * radius;
}
public double getRadius() {
return radius;
}
public String toString() {
String str;
str = "Radius: " + radius + "Area: " + getArea();
return str;
}
public boolean equals(Circle c) {
boolean status;
if (c.getRadius() == radius)
status = true;
else
status = false;
return status;
}
public boolean greaterThan(Circle c) {
boolean status;
if (c.getArea() > getArea())
status = true;
else
status = false;
return status;
}
}
I have created a class also to test this class below is the class: -
MainCircle.java
public class MainCircle {
public static void main(String args[]) {
Circle c = new Circle(2.5);
Circle c1 = new Circle(2.5);
Circle c2 = new Circle(4.5);
System.out.println(c);
System.out.println(c1);
System.out.println(c2);
System.out.println("Is c and c1 equal : "+c.equals(c1));
System.out.println("Is c2 greater than c1 : "+c1.greaterThan(c2));
}
}
Output: -
Radius: 2.5Area: 19.634954084936208
Radius: 2.5Area: 19.634954084936208
Radius: 4.5Area: 63.61725123519331
Is c and c1 equal : true
Is c2 greater than c1 : true