public class Circle implements Areable {
protected double r;
@Override
public double getArea() {
return r * r * Math.PI;
}
public double getR() {
return r;
}
public void setR(double r) {
this.r = r;
}
public Circle(double r) {
super();
this.r = r;
}
}
public class Rectanle implements Areable {
protected double x;
protected double y;
@Override
public double getArea() {
// TODO Auto-generated method stub
return x * y;
}
public Rectanle(double x, double y) {
super();
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
}
public class AreaComparator {
public String compare(Areable a1, Areable a2) {
if (a1.getArea() > a2.getArea()) {
return "CircleArea > RectangleArea";
} else if (a1.getArea() < a2.getArea()) {
return "CircleArea < RectangleArea";
} else {
return "CircleArea = RectangleArea";
}
}
}
public class AreaCompatorTest {
public static void main(String[] args) {
Areable a1 = new Circle(2.5);
Areable a2 = new Rectanle(2.0, 3.0);
String result = new AreaComparator().compare(a1, a2);
System.out.println(result);
}
}