Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:42:25+00:00 2026-06-13T05:42:25+00:00

I am creating a simple program to calculate proximity distance measures of coordinates read

  • 0

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 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:42:26+00:00Added an answer on June 13, 2026 at 5:42 am

    A Integer can not represent a coordinate. You can create something like –

    public class Coordinate {
        private int x;
        private int y;
    
        //...getter/setter/constructor ...
    }
    

    which can represent a coordinate.

    And instead of (list of just integers)

    ArrayList<Integer> coordinates = new ArrayList<Integer>();
    

    use (list of coordinates)

    List<Coordinate> coordinates = new ArrayList<Coordinate>();
    

    Now, if you define a method as @Hovercraft suggested (for Coordinate) it will be really easy to calculate distance between all the points to all other points (including itself)

    for(int i=0; i<coordinates.size(); i++) {
        for(int i=0; i<coordinates.size(); i++) {
            System.out.println(manhattnDist(coordinates.get(i), coordinates.get(j)));
        }
    }
    

    One obvious problem in your code

        int distance = 0;
        for(int ii=0;ii<x.size();ii++) {
            for(int jj=0; jj<x.get(ii).coordinates.size();jj++) {
                 //you keep assigning new values 
                 distance = Math.abs(x.get(ii).coordinates.get(jj)) + Math.abs(x.get(ii).coordinates.get(jj));
            }   
            //and then you add
            result.add(distance);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a simple program to track notes into a text file. I
I am creating a simple math program with 6 different problem types. I want
I am creating a simple reporting program using java and iReport (from jasper), which
I am making a simple program which suppose to accept txt file data from
I'm creating a simple program with the possibility to change the language and I
I'm creating a simple file walker to list some files and need to omit
We have a fairly simple program that's used for creating backups. I'm attempting to
I have made a program in Flex for creating simple schedules, similar to MS
I am teaching myself Common Lisp and I'm creating a simple program that interfaces
I'm creating this simple program which would save me alot of time, but I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.