Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Add objects to the neighbors list

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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


  2. #2
    Member
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    70
    My Mood
    Cool
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default 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??

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

Similar Threads

  1. Add an object to a linked list and a database
    By a21j92 in forum JDBC & Databases
    Replies: 0
    Last Post: March 2nd, 2013, 10:09 AM
  2. Do you add objects to an array when using switch statement with a For loop?
    By TheWhopper858 in forum Collections and Generics
    Replies: 2
    Last Post: November 13th, 2011, 01:28 PM
  3. override list add method?
    By ober0330 in forum Collections and Generics
    Replies: 10
    Last Post: July 17th, 2011, 07:34 PM
  4. Operate on list`s objects
    By MryJaho in forum Java Theory & Questions
    Replies: 5
    Last Post: February 24th, 2011, 05:44 AM
  5. Java Newbie: How to Code Node and its Neighbors?
    By ke3pup in forum Java Theory & Questions
    Replies: 0
    Last Post: April 20th, 2010, 01:00 AM

Tags for this Thread