Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 13 of 13

Thread: Word Search

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Word Search

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Word Search

    file which is a two dimensional character array
    Can you explain what that means?
    Is one dimension the line/row in the file
    and the other dimension the characters in the line?

    That is the normal format (or content) of a text file.

    Is there more than one word in a line?

    Is the assignment required to treat the contents of a line as an array of char? In other words, you can not use Strings. The posted code is converting the char array to a String. Why not read the line from the file as a String?

    Can you explain why you need to search up or to the left?

    I'm confused about why the char array when that is the same as a String.

    Please wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Word Search

    Does each method search the array from a given row, column location in a fixed direction for a match with the characters passed to it in a String? There are 4 methods, one for each direction.
    Up and down go by rows, left and right go by columns.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Word Search

    OK. Which method are you working on and what problems are you having designing and coding it?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Word Search

    Quote Originally Posted by Norm View Post
    OK. Which method are you working on and what problems are you having designing and coding it?



    So far I have finished the method to create and return a two dimensional array and prompted the user for the name of the datat file to open and read into the array and the method to print the puzzle to the screen one row at a time. I'm having trouble with the play method which has the string word and char[][] puzzle parameters that is supposed to check the first character of the word string to each character in the puzzle until there is a match.

    I know that this is where i'm supposed to call the methods for up down left and right but i can't get that far. Anything would be extremely helpful at this point.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Word Search

    supposed to check the first character of the word string to each character
    That sounds like you need a loop to compare against the characters in the array.
    Is only the first letter used? What characters in the array are to be checked?
    When a match is found, what next?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Word Search

    Quote Originally Posted by Norm View Post
    That sounds like you need a loop to compare against the characters in the array.
    Is only the first letter used? What characters in the array are to be checked?
    When a match is found, what next?
    If the first letter of the string matches a character in the array then it check the second letter of the string against the next character in the array. If its found then it prints so and moves on to the next word in the string to compare it to the characters in the array (puzzle). This continues until all the words in the string are tested.

    I'm not sure if that made sense.
    How can I use a loop to do that? Do I use string position? Character position?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Word Search

    The characters in a String can be accessed a couple of ways: all at once or one by one. See the String class for methods to used.

    There are two parts to the search:
    first find a match of the first character somewhere in the array
    then look in the 4 directions for the rest of the chars in the String (your 4 methods should do that)

    To look at all the elements in a 2 dim array will take one loop nested inside another loop
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Word Search

    Yeah I know essentially what I need to just not exactly how to do it.

    Thanks anyway!

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Word Search

    Take it one step at a time. First write nested loops to go through the 2 dim array and print out its contents by row and column.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Word Search

    Where are the source statements with the errors? Lines 52 and 63


    What is the fill() method supposed to do with what it reads from the file?
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Word Search

    What is line 52 supposed to do? To store data into a slot in an array, the code needs to provide indexes for each dimension. The []s should not be empty.

    What is line 63 supposed to do? The file variable is a reference to a File class object. The compiler wants there to be a variable that contains one dim int arrays that can be returned one by one into the row variable.

    The fill() method is supposed to create and return a 2D char array
    What are the steps the program must do to get the data from the file into a 2 dim array?
    If the program reads a line into a String, what will the program do with that String?
    Are all the lines in the file the same length?
    How many lines are there in the file?

    Can you give a sample file's contents and show where its contents would go in the array?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Word Search

    I suggest you start over. Write the code for the method one small step at a time instead
    of trying to write it all at once. If there are compiler errors, fix them before writing any more code.

    Make a list of the steps the fill() method needs to do
    and work on doing the first item in the list. When that compiles and executes ok, move to the next step. Don't move to the next step until the current step compiles and executes without problems.

    How did the posted code get all the leading *s? That makes it very hard to copy the code for testing.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 7
    Last Post: March 29th, 2013, 07:38 AM
  2. Replies: 5
    Last Post: August 20th, 2012, 01:01 AM
  3. Reading a text file word by word
    By dylanka in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 21st, 2011, 02:06 PM
  4. Word Search Help
    By Tanner in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 3rd, 2011, 01:39 AM
  5. Search Word puzzle game
    By lew1s in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 9th, 2011, 04:23 AM