Help needed with boolean method

Hello eveybody
I'm trying to write a program to find a word in a Word Search Puzzle.

I have a method checkWord to find the first letter.
Then it calls method searchAround to find the other letters. SearchAround is a boolean method, but I don't know how or where to place the return statement (true or false)
I'm attaching a Word document with the methods the way I have them so far (I don't have access to NetBeans right now, that's why I'm typing the code in Word).
Please help me with this boolean method and pelase, if you notice anything else that is wrong let me know to keep working on it.
I'm inserting the code here anyways:
[code]
//method to find the word
public void checkWord (String word)
{
for (int i=0; i= 0 && posx < boardarray.length) &&
(posy >=0 && posy < boardarray[posx].length);
}//end of validatePosition

[/code]

Comments

  • frank,
    The return is positioned where the logic has determined that method is / or can not be satisfied.
    This is not a trivial problem in my opinion. My first instinct is to break it down into simpler tasks. You recognize there are 8 directions a word could occur in. I would use a separate method to search in each direction. I drew a picture to visualize the searches needed.
    I would have expected this problem to require identification the word, and its location, ie start point, direction, and length.

    Hope this helps,
    se52
  • I'm trying to break it into simpler methods, but I don't find the way
    How would you do a method for each direction?
    For this problem I have the array already declared as well as the word to find. I have to find the start point, direction and length.
    Any help?
  • frank,
    here is sample code to search through a wordJumble array in the left to right direction:
    [code]public class TestCode {

    public static void main(String... args) {
    testFindWord();
    }

    public static void testFindWord() {
    char[][] wordJumble = {{'n', 'o', 'w', ' ', 'i', 's', 't', 'h', 'e'},
    {'t', 'i', 'm', 'e', ' ', 'f', 'o', 'r', ' '},
    {'g', 'o', 'o', 'd', 't', 'i', 'm', 'e', 's'}};
    String searchWord = "or";
    searchLeftToRight(wordJumble, searchWord);
    }

    public static void searchLeftToRight(char[][] wordJumble, String searchWord) {
    StringBuilder charString; // holds sub strings within a wordJumble line
    // examine each row in the array
    for (int eachRowIdx = 0; eachRowIdx < wordJumble.length; eachRowIdx++) {
    // examine each "subword" within a row
    for (int eachSubWordIdx = 0; eachSubWordIdx <= wordJumble[eachRowIdx].length - searchWord.length(); eachSubWordIdx++) {
    charString = new StringBuilder("");
    // build one charString to match against the searchWord
    for (int eachRowChar = eachSubWordIdx; charString.length() <= searchWord.length(); eachRowChar++) { //build a charString
    if (charString.length() < searchWord.length()) {
    charString.append(wordJumble[eachRowIdx][eachRowChar]);
    } else {
    if (charString.toString().equalsIgnoreCase(searchWord)) {
    System.out.printf("%nfound search word: "%s" searching Left-to-Right " +
    "in row %d column %d%n%n", searchWord, eachRowIdx, eachRowChar - searchWord.length());
    }
    break;
    }
    }
    }
    }
    }
    }[/code]

    gl, se52
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories