• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HeadFirstJava - DotCom application

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is 0.
 
reply
    Bookmark Topic Watch Topic
  • New Topic