• 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

Array creation code not working

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys,

I'm really new to Java, only been learning it for a week and I've been reading through Head First Java. I'm on chapter 6 now and I wanted to try to make the DotCom game by myself (for those who haven't read the book, it's basically a Sink The Ship game on a 2d array). I Know I already have the code in the book, but I have written the code already and what isn't working in my code is that my code won't create an array of locations for the 3 "ships". And since you learn best at your own mistakes, I would be really happy if somebody would tell me what is wrong in my code. Also, ask any questions you have and sorry if this question is kinda stupid.

Here is the code for the method randoming 2 numbers from 1-5 and then converting it into a string (A3 for example), randoming the direction number and then putting the three locations into an ArrayList array. The problem is, when I run the test code for the method, the location array doesn't seem to be created as every guess returns a "miss".



Again, I haven't commented the code, but I tried to explain it in the question, so if you have any questions, I'd be happy to answer them.

Thank you very much,
Leon
 
Leon Zaher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the double post, but I realised the code is working when I used it with the whole game code.
 
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic