This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.
public Point[] extremes() {
if (this.isEmpty())
return null;
// left, right , top, bottom
Point left = null, right = null, top = null, bottom = null;
Point returnArray[] = new Point[4];
double xLeft = points[0].getX();
double xRight = points[0].getX();
double yUp = points[0].getY();
double yDown = points[0].getY();
for (int i = 1; i < size; i++) {
if (points[i].getX() < xLeft) {
xLeft = points[i].getX();
left = points[i];
} else if (points[i].getX() > xRight) {
xRight = points[i].getX();
right = points[i];
}
}
for (int j = 1;j<size; j++) {
if (points[j].getY() > yUp) {
yUp = points[j].getY();
top = points[j];
} else if (points[j].getY() < yUp) {
yDown = points[j].getY();
bottom = points[j];
}
}
returnArray[0] = left;
returnArray[1] = right;
returnArray[2] = top;
returnArray[3] = bottom;
return returnArray;
}
public Point[] extremes() {
if (this.isEmpty())
return null;
// left, right , top, bottom
Point left = null, right = null, top = null, bottom = null;
Point returnArray[] = new Point[4];
double xLeft = points[0].getX();
double xRight = points[0].getX();
double yUp = points[0].getY();
double yDown = points[0].getY();
for (int i = 0; i < size; i++) {
if (points[i].getX() < xLeft) {
xLeft = points[i].getX();
left = points[i];
} else if (points[i].getX() > xRight) {
xRight = points[i].getX();
right = points[i];
}else if (points[i].getY() > yUp) {
yUp = points[i].getY();
top = points[i];
} else if (points[i].getY() < yDown) {
yDown = points[i].getY();
bottom = points[i];
}
}
returnArray[0] = left;
returnArray[1] = right;
returnArray[2] = top;
returnArray[3] = bottom;
return returnArray;
}
public Point[] extremes() {
if (this.isEmpty())
return null;
// left, right , top, bottom
Point left = null, right = null, top = null, bottom = null;
Point returnArray[] = new Point[4];
double xLeft = points[0].getX();
double xRight = points[0].getX();
double yUp = points[0].getY();
double yDown = points[0].getY();
for (int i = 0; i < size; i++) {
if (points[i].getX() < xLeft) {
xLeft = points[i].getX();
left = points[i];
} else if (points[i].getX() > xRight) {
xRight = points[i].getX();
right = points[i];
}
if (points[i].getY() < yDown) {
yDown = points[i].getY();
bottom = points[i];
} else if (points[i].getY() > yUp) {
yUp = points[i].getY();
top = points[i];
}
}
returnArray[0] = left;
returnArray[1] = right;
returnArray[2] = top;
returnArray[3] = bottom;
return returnArray;
}
Point left = points[0], right = points[0], top = points[0], bottom = points[0];
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
also, shouldn't your arrays start with 0?