• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rewrites  RSS feed

 
Dale Herring
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.



 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!