public abstract class Shape implements Comparable
{
public
abstract double area( );
public
abstract double perimeter( );
public int
compareTo( Object rhs )
{
Shape
other = (Shape) rhs;
double
diff = area( ) - other.area( );
if( diff
== 0 )
return 0;
else if(
diff < 0 )
return -1;
else
return 1;
}
public double
semiperimeter( )
{
return
perimeter( ) / 2;
}
}
Package java.lang;
// Figs 4.15 & 4.16, pg 110-1
public interface Comparable
{
int
compareTo( Object other );
}