0

Hey guys, I'm stuck at a problem. Check out the code:

```
import java.util.*;
class testAll
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
ArrayList pointsArray = new ArrayList();
ArrayList linesArray = new ArrayList();
System.out.println("Enter amount of sides: ");
int sides = input.nextInt();
if (sides <= 2 || sides > 6)
{
System.out.println("Error in creating polygram");
}
else
{
for (int i = 0; i < sides + 1; i++)
{
System.out.println("Enter the X coordinate: ");
int a = input.nextInt();
System.out.println("Enter the Y coordinate: ");
int b = input.nextInt();
Point P = new Point();
P.create(a, b);
pointsArray.add(P);
}
for (int i = 0; i < pointsArray.size() - 1; i++)
{
Point P1 = (Point) pointsArray.get(i);
Point P2 = (Point) pointsArray.get(i + 1);
Line L1 = new Line();
L1.create(P1, P2);
linesArray.add(L1);
L1.display();
L1.length();
System.out.println();
}
linesArray.size();
}
}
}
```

I have to allow the user to enter the amount of sides they want to enter (no less than 2 and no more than 6), and then I have to calculate the perimeter of the created polygon.

So far I have been able to get the following output which looks a bit like this:

```
Enter amount of sides:
3
Enter the X coordinate:
1
Enter the Y coordinate:
2
Enter the X coordinate:
3
Enter the Y coordinate:
2
Enter the X coordinate:
2
Enter the Y coordinate:
23
Enter the X coordinate:
23
Enter the Y coordinate:
1
Point 1 = (1,2)
Point 2 = (3,2)
The length of the line is: 2.0
Point 1 = (3,2)
Point 2 = (2,23)
The length of the line is: 21.02379604162864
Point 1 = (2,23)
Point 2 = (23,1)
The length of the line is: 30.4138126514911
```

I am now stuck at trying to add the results of the lines lengths and add them all together, to output the perimeter of the polygon. Any help would be appreciated ;-)