Results 1 to 9 of 9
  1. #1
    nethz13 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default how do you make comparison between vectors?

    code i try is like
    Java Code:
    if (getVelocity() [COLOR="Red"]equals (20.0, 0.0))[/COLOR]{
            setBodyImage(new BodyImage("st1mob2walkR.gif"));
    i am not sure about the red bit,
    however I used system println for getVelocity(), which shows on the terminal are vectors (20.0,0.0)[I also check the doc.]
    what should I do to make the red bit working as I was intended?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The Vector (or better its parent, AbstractList) API has important information about the equals method that is pertinent here. But having said that, the amateur physicist in me makes me think that this Vector holds velocity information, and that you'll want to set your body image to a "walking(?)" image if the speed is > something and < something else. If so then your approach will need to change.

  3. #3
    nethz13 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    The Vector (or better its parent, AbstractList) API has important information about the equals method that is pertinent here. But having said that, the amateur physicist in me makes me think that this Vector holds velocity information, and that you'll want to set your body image to a "walking(?)" image if the speed is > something and < something else. If so then your approach will need to change.
    yes.. but >something or <something does not apply on getVelocity()
    and getVelocity() is the only good way I have, to determent the monster is walking left or right..
    but just in short, the info like (20.0,0.0) is comparable or not?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by nethz13 View Post
    but just in short, the info like (20.0,0.0) is comparable or not?
    In short, yes it is. You may use the equals method, but I'd advise you read the section on it in the AbstractList API.

  5. #5
    nethz13 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    In short, yes it is. You may use the equals method, but I'd advise you read the section on it in the AbstractList API.
    I must having something seriously wrong here..
    I tried getVelocity().equals(0.0) which the code will compile but its velocity is change to 0.0 when I touch it..

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You can't compare a Vector to a double but rather only to another Vector. In fact that's one of the basic rules when using the equals method: you can only compare one object with another object of the same class.

  7. #7
    nethz13 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    You can't compare a Vector to a double but rather only to another Vector. In fact that's one of the basic rules when using the equals method: you can only compare one object with another object of the same class.
    yes, that is what i read from the book as well. does it mean I have no way to make some number and use equals to compare with it?
    and if equals is not good, any more suggestions? Thanks..

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by nethz13 View Post
    yes, that is what i read from the book as well. does it mean I have no way to make some number and use equals to compare with it?
    and if equals is not good, any more suggestions? Thanks..
    Who said equals is "not good"? You need to compare one Vector with another Vector, that's all.

  9. #9
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    do those doubles exist in the constructor?

    i don't know this class specifically but wouldn't something like

    vector1.equals(new Vector(double1, double2));

    work

    ??

    yeah uhm, i just looked at the api for vector and it's kind of strange, suggest you do what fub suggested, read that api front and back, and the class it extends from.
    Last edited by Cruncher; 04-19-2010 at 03:00 AM.

Similar Threads

  1. String Comparison
    By evant8950 in forum Java Applets
    Replies: 6
    Last Post: 04-22-2009, 09:11 AM
  2. Vectors of Vectors or hash-somethings?
    By mindwarp in forum New To Java
    Replies: 3
    Last Post: 03-10-2008, 03:57 PM
  3. Comparison of Strings
    By Cero.Uno in forum New To Java
    Replies: 3
    Last Post: 02-11-2008, 03:46 AM
  4. Date comparison
    By Rageagainst20 in forum New To Java
    Replies: 0
    Last Post: 12-19-2007, 07:34 PM
  5. String comparison
    By sireesha in forum New To Java
    Replies: 1
    Last Post: 12-18-2007, 01:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •