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

WHAT IS WRONG WITH MY PROGRAM AND WHY ARE THERE ERRORS ON MY INTERFACE??? <><><>

ID: 3848707 • Letter: W

Question

WHAT IS WRONG WITH MY PROGRAM AND WHY ARE THERE ERRORS ON MY INTERFACE???

<><><><>Shape1.java:<><><><>

public interface Shape1{

public double getArea;

   public double getPerimeter;

}

<><><><>Hexagon.java:<><><><>

public class Hexagon implements Shape1{

   double side;

       public Hexagon(double side){

           this.side = side;

       }

       public double getArea(){

return (side*side)*((3.0*Math.sqrt(3.0))/2);

       }

       public double getPerimeter(){

           return 6*side;

       }

   }

.Hexagon Main.java shape ava 1 public interface Shape11 public double getArea; public double getPerimeter; 8 public class Hexagon implements Shape11 10 double side 11 public Hexagon double side) 123 this side side 14 15 public double get Area 18 return Cside side) CC3.0 Math.sartC3.0) /2); 19 20 22 public double getPerimeter 233 return 6 side; 32 33

Explanation / Answer

Problem in the code:

1. The getArea and getPerimeter are declared as data members instead of functions

2. Both interface Shape1 and the class Hexagon should be declared in seperate file as they are public.

3. To test run the class, we need to specify main function.

Solution program:

Shape1.java
public interface Shape1{
public double getArea();
public double getPerimeter();
}

Hexagon.java

public class Hexagon implements Shape1 {//implementing interface Shape1

double side;//variable to store side of the hexagon
public Hexagon(double side){//constructor to initialize object of Hexagone
this.side=side;
}
@Override
public double getArea() {//overridden function to calculate area of hexagon
return (side * side)*((3.0*Math.sqrt(3.0))/2);
}

@Override
public double getPerimeter() {//overridden function to calculate perimeter of hexagon
return 6*side;
}
public static void main(String args[]){
Hexagon obj=new Hexagon(5);//creating object
System.out.println(obj.getArea());//function call to get area
System.out.println(obj.getPerimeter());//function call to get perimeter
}
}