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

Write a program named Test_2.java. In the class implement the main function to t

ID: 3620714 • Letter: W

Question

Write a program named Test_2.java. In the class implement the main function to test how your program runs. 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 Test_2 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)



}
}

Explanation / Answer

public Hexagon(double side) { // save constructor parameters in instance variables this.side = side; } public double findArea() { // area of a hexagon is side*3sqrt(3)/2 return side*1.5*Math.sqrt(3); } public double findPerimeter() { // a hexagon has 6 sides return side*6; } public int compareTo(Object obj) { // compare 2 hexagons based on area // equivalent to comparing by side Hexagon rhs = (Hexagon)obj; if(side > rhs.side) return 1; else if(side
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