Question: loadMazeThis method reads a maze file and sets up the corresponding fields accordingly. Since it is reading from a file, it can throw a FileNotFoundException,
loadMazeThis method reads a maze file and sets up the corresponding fields accordingly. Since it is reading from a file, it can throw a FileNotFoundException, which must be declared since we have not learned about catching exceptions yet.First, it should create our five array fields: blocked, visited, player, start, and goal. Initialize them to empty dimensional or dimensional depending on the field arrays of appropriate sizes. After creating these arrays in loadMaze, all of the tests for the getters and setters should pass consider whyNext, you will need to open the maze file using a Scanner, read in the data, and set values accordingly. Here are some hints:Remember that to read from a file you will need to pass the Scanner a file object, not just the file name.Use nested for loops to loop through the blocked array. The outer index variable is the row, the inner index variable is the column.Read the file one character at a time using the next function not nextLineRead in the next character in the inner for loop.If the character is a set the corresponding location in the blocked array to true.If the character is a set the corresponding location in the blocked array to false;If the character is an S set the location of the start and player, since the player starts at the starting location.If the character is a G set the location of the goal.This would be a great place to use a switch statement, although you are not required toThe tests for both constructors should pass now
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
