• Post Reply Bookmark Topic Watch Topic
  • New Topic

HeadFirstJava - DotCom application  RSS feed

 
Negru Ionut Valentin
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DotCom class

DotComBust class

GameHelper class


I have this 3 classes(above).
My application runs without errors but it doesn't work correctly.
For example if i have for one DotCom Object this coords:
coord 1 = b3 coord 2 = b4 coord 3 = b5
when i enter b3 it says Ratat(Miss), but for b4 and b5 it says Lovit(Hit) so i can't destroy any DotCom object.
It's the same for all 3 Objects.
I can't figure out where it is the problem, i rechecked the program 2 times with the book but everything seems ok.
Can anyone please tell me what i'm doing wrong ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DotCom.java

Check the returned value for the indexOf method, in java.util.List, and you will understand why the first value is never found.
 
Negru Ionut Valentin
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have checked that indexOf method, and as i understood it says that it returns the index of the first match of the specified element in the list.
But i still can't understand why the first one is never found and the next two are found correctly.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know what the index is for the first element of a list ? Is it 0 ? Or is it 1 ?
 
Negru Ionut Valentin
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is 0.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!