# Add objects to the neighbors list

• January 8th, 2014, 11:14 PM
soleil
Add objects to the neighbors list
I have a java exercise follow: there are n machines of 3 type A,B,C, each machine has coordinates (x,y) and operate radius, with data get from a XML file, for instance:
Code :

```<machine> <number ="1"> <type>C</type> <cox>40</cox> <coy>80</coy> <rad>30</rad> </number> <number ="2"> <type>A</type> <cox>25</cox> <coy>35</coy> <rad>40</rad> </number> <number ="3"> <type>C</type> <cox>50</cox> <coy>10</coy> <rad>50</rad> </number> </machine>```

I made 3 class A, B, C and already got information from xml file. But the 2 problems is that:

1. calculate the distance between each machine

2. add them to list of each machine if distance is less than radius.

I known the formula to calculate the distance but dont know how to get x, y to calculate nx(n-1) distances, and add them to list. Could anyone give me the idea to solve these 2 problems? Thank so much! :o
• January 9th, 2014, 09:46 PM
dineshj83
Re: Add objects to the neighbors list
when you meant you got the information from xml file it contains x and y co-ordinates as well as child nodes. Then you have them as well for your calculation. Are you not sure of how to parse xml is that these question here??
• January 10th, 2014, 02:23 AM
soleil
Re: Add objects to the neighbors list
Thank dineshj, i have done the first job (calculate the distance between each machine), my main question is how to add the neighbor machines to the list of each object. I think solution about add attribute List to the 3 class A, B, C (using arraylist). Then, when read from the xml, it will show the neighbor list of each object. I m coding now but not yet done.