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:

<number ="1">
<number ="2">
<number ="3">

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!

This article has been dead for over six months. Start a new discussion instead.