Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class named Hexagon that extends Geometric Object and implements the Com

ID: 3807975 • Letter: W

Question

Write a class named Hexagon that extends Geometric Object and implements the Comparable interface. Assume all six sides of the hexagon are of equal size. The Hexagon class is defined as follows: public class Hexagon extends Geometric Object implements Comparable {private double side;/** Construct a Hexagon with the specified side */public Hexagon(double side) {//Implement it}/** Implement the abstract method getArea in GeometricObject */public double getArea() {//Implement it (area = 3 * Squareroot 3 * side * side)}/** Implement the abstract method getPerimeter in GeometricObject */public double getPerimeter() {//implement it}/** implement the compareTo method in the Comparable interface to */public int compareTo (object obj) {//Implement it (compare two Hexagons based on their areas)

Explanation / Answer


@SuppressWarnings("rawtypes")
public class Hexagon extends GeometricObject implements Comparable {
  
   private double side;
  
   public Hexagon(double side){
       this.side = side;
   }
  
   public double getArea(){
       return (3*Math.sqrt(3)*this.side*this.side);
   }
  
   public double getPerimeter(){
       return 6*this.side;
   }
  
   public int compareTo(Object obj){
       Hexagon h;
       if(obj instanceof Hexagon){
           h = (Hexagon)obj;
           return (int) (this.getArea()-h.getArea());
       }
       else
           return 0;
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote