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

JAVA POGRAM ... Quick one !! Need it ASAP Fill in parts of code writing a class

ID: 3580765 • Letter: J

Question

JAVA POGRAM ... Quick one !! Need it ASAP
Fill in parts of code writing a class called Hexagon. We have to write the constructor method, a method to calculate the area, and a method to calculate the area. We also have to write a compareTo method comparing to objects of type Hexagon. We have to create an equals method to see if two Hexagons are equal. We have to write a toString method as well.


JAVA POGRAM ... Quick one !! Need it ASAP
Fill in parts of code writing a class called Hexagon. We have to write the constructor method, a method to calculate the area, and a method to calculate the area. We also have to write a compareTo method comparing to objects of type Hexagon. We have to create an equals method to see if two Hexagons are equal. We have to write a toString method as well.



Fill in parts of code writing a class called Hexagon. We have to write the constructor method, a method to calculate the area, and a method to calculate the area. We also have to write a compareTo method comparing to objects of type Hexagon. We have to create an equals method to see if two Hexagons are equal. We have to write a toString method as well.


Explanation / Answer

public class Hexagon{
    public double side;

    public Hexagon(double side){
        this.side = side;
    }

    public double getPerimeter(){
        return this.side * 6;
    }

    public double getArea(){
        return 3*Math.sqrt(3)/2 * Math.pow(this.side, 2);
    }

    public boolean compareTo(Hexagon hexagon){
        return this.side > hexagon.side;
    }

    public boolean equals(Hexagon hexagon){
        return this.side == hexagon.side;
    }

    public String toString(){
        s = "Side: " + side;
        s += "Area: " + getArea();
        s += "Perimeter" + getPerimeter();
        return s;
    }

}