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

hi, I need a recursive method in java to compute the area of a hexagon, can anyo

ID: 3532598 • Letter: H

Question

hi, I need a recursive method in java to compute the area of a hexagon, can anyone help? This is the iterative version of the program and I was told it could be used as my guide. Although all I really need is just the recursive method.

importjava.text.DecimalFormat;
public class polygon_area{
public static void main(String[] args){
DecimalFormat fmt = new DecimalFormat("0.0000");
double [] x = {7.5774,6.4226,4.3453,3.4226,4.5724,6.6547};
double [] y = {4.6340,6.3660,6.2321,4.3660,2.6340,2.7679};
double area = 0;
for(int i = 0;i<1;i++)
area+=(x[0]*y[i+1]+x[1]*y[i+2]+x[2]*y[i]-y[0]*x[i+1]-y[1]*x[i+2]-y[2]*x[i])/2.;
System.out.println("the area is: "+fmt.format(area));
}
}

thank you for your help in advance.

I have had some bad experiences with chegg in the past and I am looking for a reason to stay with chegg.  

I would just like to state that I WILL NOT rate any

Explanation / Answer

The recursive implementation of your function is here however I don't know how this can give area of a hexagon since it is using only 3 of the 6 points of hexagon. The for loop is working for only i=0 since the condition imposed is i<1. Please fo through with the formula for area for once. I have only given the recursive implementation of the function you have provided.


importjava.text.DecimalFormat;

public class polygon_area{


public double recursive(double x[], double y[] , int i)

{

if(i==3)

return 0;

return x[i]*y[((i+1)%2)] - y[((i+1)%2)]*x[i] + recursive(x,y,i+1);

}


public static void main(String[] args){

DecimalFormat fmt = new DecimalFormat("0.0000");

double [] x = {7.5774,6.4226,4.3453,3.4226,4.5724,6.6547};

double [] y = {4.6340,6.3660,6.2321,4.3660,2.6340,2.7679};

double area = 0;

area=recursive(x,y,0) / 2.;

System.out.println("the area is: "+fmt.format(area));

}

}