• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin


Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wondering if someone can help me with this program. The biggest issue is that when it "gets arrested" I.E. hits a point where it can not find a dot to move to because a letter or the end of grid is there, it gets an out of bounds exception which I have tried to bounds check. Occasionally it will do something like skip over a letter while still printing both or moving diagonally, but those are rare. The only other tiny issue is it not printing Z when it "makes it home". I am sure there's an easy way to do this just not sure without it breaking my code.

Posts: 79261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That method is far too long. Remove all those loops; they belong in their own methods, in their own class. Search my posts for, “utility class”, and you should find enough information to make your ownutility class, but you won't find everything in one thread. You should create a utility class to do all that keyboard input. Then reuse that utility class for ever.
A main method has an ideal length: one statement.
That switch statement is far too long. Remove each part of the switch into its own method. It should read something like this:-Remember you can use enum constants after case, or (Java7+ only), Strings. If you use an enum, there is no risk of getting an invalid argument.

Now put some debugging print statements into your code. Whenever you get near the arrest method print the values of your variables, so you can see what is happening.
    Bookmark Topic Watch Topic
  • New Topic