Can you explain what that means?Quote:
file which is a two dimensional character array
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:
<YOUR CODE HERE>
to get highlighting and preserve formatting.
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.
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.
That sounds like you need a loop to compare against the characters in the array.Quote:
supposed to check the first character of the word string to each character
Is only the first letter used? What characters in the array are to be checked?
When a match is found, what next?
I'm not sure if that made sense.
How can I use a loop to do that? Do I use string position? Character position?
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
Yeah I know essentially what I need to just not exactly how to do it.
Thanks anyway! :)
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.
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?
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.
What are the steps the program must do to get the data from the file into a 2 dim array?Quote:
The fill() method is supposed to create and return a 2D char 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?
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.