• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

HeadFirstJava - DotCom application

 
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 ?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • 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 VI Editor Ubuntu
  • 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.
 
It means our mission is in jeapordy! Quick, read this tiny ad!
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!