这几个JAVA编程题目怎么写呢?

2025-04-28 12:38:39
推荐回答(1个)
回答1:

public class Hexagon extends GeometricObject implements Comparable{
private double side;
/**Construct a Hexagon with the specified side*/
public Hexagon(double side)
{
//Implement it
this.side=side;

}
/**Implement the abstract method findArea in GeometricObject*/
public double findArea(){
//Implement it(area=3*3*side*side)
return 3*3*side*side;
}
/**Implement the abstract method findPerimeter in GeometricObject*/
public double findPerimeter(){
//Implement it
return side;
}
/**Implement the compareTo method in the Comparable interface to*/
public int compareTo(Object obj){
//Implement it(compare two Hexagons based on their areas)
Hexagon h = (Hexagon)obj;
return Double.valueOf(this.findArea()).compareTo(Double.valueOf(h.findArea()));
}
}