import java.util.*;
public class polygonrunner
{
public static void main(String[] args)
{
//Creater an object and array
Scanner in = new Scanner(System.in);
polygon PolygonW = new polygon();
ArrayList<Double> PolygonX = new ArrayList<Double>();
ArrayList<Double> PolygonY = new ArrayList<Double>();
double[] PolygonZ = new double[2];
int count=0,check=0;
//get Value
do
{
System.out.print("Enter the position X : ");
PolygonX.add(in.nextDouble());
System.out.print("Enter the position Y : ");
PolygonY.add(in.nextDouble());
count++;
if(count==3)System.out.print("Thisis become a triangle.\n");
else if(count==4)System.out.print("Thisis become a rectangle.\n");
else if(count>=5)
{
System.out.print("Do you want to add more point (1=Y,2=N): ");
check=in.nextInt();
}
}while(check!=2);
int i,j,k;
i=PolygonX.size();
j=PolygonY.size();
//process Parimeter
for(k=0;k<i-1;k++)
{
PolygonZ[0]=PolygonW.perimeter(PolygonX.get(k),PolygonX.get(k+1),PolygonY.get(k+1),PolygonY.get(k+1));
}
//process Area
for(k=0;k<i;k++)
{
PolygonZ[1]=PolygonW.area(PolygonX.get(k),PolygonY.get(k+1),k,i);
if(k+1>j-1)
{
PolygonZ[1]=PolygonW.area(PolygonX.get(k),PolygonY.get(0),k,i);
}
System.out.println("Parimetr of this Shape"+PolygonZ[0]);
System.out.println("Area of this Shape"+PolygonZ[1]);
}
}
}
////////////////////////////
เซฟชื่อ polygonrunner.java
คอมไฟล์แล้วรันได้เลย
///////////////////////////