I have this code :
import java.awt.Point;
import java.util.Arrays;
public class Haupt {
// creates an array of anz Point objects
public static Point[] generatePointArray(int anz) {
Point[] pa = new Point[anz];
for(int i = 0; i < anz; i++) {
int px = (int) (Math.random() * 10);
int py = (int) (Math.random() * 10);
pa[i] = new Point(px,py);
}
return pa;
}
public static void main(String[] args) {
Point[] pointArray = generatePointArray(15);
Arrays.sort(pointArray);
for(int i = 0 ; i < pointArray.length; i++) {
System.out.println("Point: "+pointArray[i] +
" has distance "+pointArray[i].distance(0,0)+
" from origin");
}
}
}
And as you may see I want to sort a point Array, therefore I wrote (nearly) a comparable :
import java.awt.Point;
public class MyPoint extends Point implements Comparable {
public int compareTo(Object o)
{
Point p = (Point) o;
if () {
return -1;
}
if () {
return 1;
}
return 0;
}
}
What do I need to write inside the if()
clause?
Edit: From the comments
The condition would be that I look after the value of the distance between the point(0,0) and Point (x,y) (If this is even possible