在GeometricObject类中定义一个静态的求两个对象较大者的max方法。实现Comparable接口。设计一个正方形类,继承GeometricObject类,实现Comparable接口,编写一个测试程序TestGeometricComparable,使用max方法求出圆和正方形的面积较大者。使用toString输出较大面积者。
publicabstractclass GeometricObject {
private String color = "white";
privatebooleanfilled;
private java.util.Date dateCreated;
/**Construct a default geometric object */
protected GeometricObject() {
dateCreated = new java.util.Date();
}
/**Construct a geometric object with color and filled value */
protected GeometricObject(String color, booleanfilled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}
/** Returncolor */
public String getColor() {
returncolor;
}
/** Set anew color */
publicvoid setColor(String color) {
this.color = color;
}
/** Returnfilled. Since filled is boolean,
* theget method is named isFilled */
publicboolean isFilled() {
returnfilled;
}
/** Set anew filled */
publicvoid setFilled(booleanfilled) {
this.filled = filled;
}