I am creating a simple program to calculate proximity distance measures of coordinates read from text file, I want to create method to calculate manhattan distance of given points for example:
(0,1,1,0,1), (1,0,0,0,1), (0,0,0,1,1)
would result in:
Item1 Item2 Item3
Item1 0 3 3
Item2 3 0 2
Item3 3 2 0
Manhattan Method:
public static void Manhattan(ArrayList<Points> x) {
ArrayList<Integer> result = new ArrayList<Integer>();
int distance = 0;
for(int ii=0;ii<x.size();ii++) {
for(int jj=0; jj<x.get(ii).coordinates.size();jj++) {
distance = Math.abs(x.get(ii).coordinates.get(jj)) + Math.abs(x.get(ii).coordinates.get(jj));
}
result.add(distance);
}
for(int ii=0;ii<result.size();ii++) {
for(int jj=0; jj<result.size();jj++) {
System.out.print(result.get(ii));
}
System.out.print(" ");
}
}
Class Point:
import java.util.ArrayList;
public class Points {
ArrayList<Integer> coordinates = new ArrayList<Integer>();
public Points (ArrayList<Integer> coordinates) {
this.coordinates = coordinates;
}
public ArrayList<Integer> getCoordinates() {
return coordinates;
}
public void setCoordinates(ArrayList<Integer> coordinates) {
this.coordinates = coordinates;
}
}
the problem is that I get weird results when I run the method, anyone knows what's the problem?
result: 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222