I'm working on a program that first takes an even array of doubles and sequentially creates a second array of (x, y) coordinates. Then, an invoking PointArray has to be compared to the argument PointArray by comparing the x-coordinates and y-coordinates of each point in the array. I know conceptually that I'll have to sort each array and compare each point using the indeces and the defined equals method, but I don't know how to refer to a point of the invoking class-type array when it is not given as a parameter.
private double x;
private double y;
public Point(double x_coord, double y_coord)
{
x = x_coord;
y = y_coord;
}
public boolean equals(Point anotherPoint)
{
if(x == anotherPoint.x && y == anotherPoint.y)
{
return true;
}
return false;
}
int count;
private Point[] points = new Point[count];
public PointArray(double[] doubleArray)
{
count = (doubleArray.length) / 2;
if(doubleArray.length % 2 == 0)
{
count = (doubleArray.length) / 2;
for(int i = 0, j = 0; i < count; i++, j += 2)
{
double x = doubleArray[j];
double y = doubleArray[j + 1];
points[i] = new Point(x, y);
}
}
else
{
System.out.println("Error: The given array must be even.");
}
}
public boolean equals(PointArray anotherPointArray)
{
double x = 0;
double y = 0;
double xAnother = 0;
double yAnother = 0;
Point newPoint = new Point(x, y);
Point newAnotherPoint = new Point(xAnother, yAnother);
anotherPointArray.sort();
anotherPointArray.newPoint;
for(int i = 0; i < points.length; i++)
{
for(int j = 0; i < anotherPointArray.length; j++)
{
if(newPoint.equals(newAnotherPoint))
{
return true;
}
}
}
return false;
}
EDIT: To clarify, my problem is that I don't know how to set up the Point equals method using the PointArray objects.