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:

<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!

You should have created a "get" method in your machine class(es) to allow other classes to access the x,y coords. (If you have designed your classes to be immutable, then it's easier to declare the instance variables as public final to make them accessible.) How have you created you "master" list of machines?
This would be easier if you post the relevant code.

I use 1 class for 3 types A,B,C and Arraylist to solve problems, and completed this exercise. Thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.