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 GeometricObject and implements the Comp

ID: 3626445 • Letter: W

Question

Write a class named Hexagon that extends GeometricObject 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 GeometricObject implements Comparable {
private double side;

/** Construct a Hexagon with the specified side */
public Hexagon(double side) {
// Implement it

}

/** Implement the abstract method findArea in
GeometricObject */
public double findArea() {
// Implement it ( )

}

/** Implement the abstract method findPerimeter in
GeometricObject */
public double findPerimeter() {
// 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)

Note: JAva Code Program

Explanation / Answer

public class Test_2 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 ( ) return 2.59807621 * this.side * this.side; } /** Implement the abstract method findPerimeter in GeometricObject */ public double findPerimeter() { // Implement it return 6 * this.side; } /** Implement the compareTo method in the Comparable interface to */ public int compareTo(Object obj) { // Implement it (compare two Hexagons based on their areas) if (this.side == ((Test_2)obj).side) // Egual return 0; else if (this.side < ((Test_2)obj).side) // Less than return -1; else // Greater than return 1; } } Try that, see if it works
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