My point class is immutable. When I am given input into the constructor originally, it should be copied into the cloneList object. This would allow for it to remain the way it was before if a couple of indexes in the array are changed via the constructor. I have tried almost every possible combination and am still running into the trouble. I want the cloneList to be a copy of the original Point[] points array, thus if the points array is changed then the cloneList will not.
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class Polygon {
private double xSum = 0;
private double ySum = 0;
private Point[] points;
private Point[] cloneList;
private Point a;
public Polygon(Point[] points) {
this.points = points;
cloneList = new Point[points.length];
for (int i = 0; i < cloneList.length; i++) {
cloneList[i] = points[i];
}
for (int i = 0; i < cloneList.length; i++)
System.out.println(cloneList[i]);
for (int i = 0; i < points.length; i++){
cloneList[i] = points[i];
// System.out.print(cloneList[i].getX());
// System.out.print(cloneList[i].getY());
// System.out.println();
}
public Point getVertexAverage() {
double xSum = 0;
double ySum = 0;
for (int index = 0; index < cloneList.length; index++) {
xSum = xSum + cloneList[index].getX();
ySum = ySum + cloneList[index].getY();
}
return new Point(xSum / getNumSides(), ySum / getNumSides());
}
public int getNumberSides() {
return cloneList.length;
}
}