import java.text.DecimalFormat; public class polygon_area{ public static void ma
ID: 3532646 • Letter: I
Question
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
please rate - thanks
import java.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.;
area=polygon(x,y,0); //send both sets of points, and the point we are processing
System.out.println("the area is: "+fmt.format(area));
}
public static double polygon(double x[],double y[ ],int point)
{
if(point==x.length-1) //is it the last point?
return (x[point]*y[0]-y[point]*x[0])/2.; //base case -last point wraps around to beginning
else
return (x[point]*y[point+1]-y[point]*x[point+1])/2.+polygon(x,y,point+1);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.