Difference of two X points? If so, you would do X1-X2...same with Y points... Y1-Y2.
To make sure the difference is positive, you can do
Math.abs(p.X1-p.X2)
likewise...
Math.abs(p.Y1-p.Y2)
then just add them together...
Math.abs(p.X1-p.X2) + Math.abs(p.Y1-p.Y2)
After your clarifications...I have revised my answer
public int manhattanDistance(Point other){ //not sure why return an int...I think returning a double makes more sense..
int xdist = Math.abs(this.x-other.x);
int ydist = Math.abs(this.y-other.y);
return (int)xdist+ydist; //cast to int because you must return int
}
or less code version...
public int manhattanDistance(Point other){
return (int)Math.abs(this.x-other.x) + Math.abs(this.y-other.y);
}