Question: Java need help with methods: This method will read the maze file and parse the maze to a 2d array of MazePoint objects. The input

Java need help with methods: This method will read the maze file and parse the maze to a 2d array of MazePoint objects. The input fileToRead is the filename of the maze you want to read.Please use Scanner 

The file contains the information of an input maze.

  1. The first line of the file will always contain two numbers. The first will represent the number of rows in the maze, while the second represents the number of columns. These numbers need not necessarily be equal.
  2. The rest of the file is the input maze:
  • Open spaces in the maze are represented by a - (minus sign). Walls are represented by a X (capital X).
  • Between every row and every column, there will be a single space.
  • No blank lines in the input file. No extra spaces between rows and columns. No extra spaces before and after each line.

Read that file and convert it to a 2d array. Close Scanner of input file after the reading is finished. You can assume that the file exists and is properly formatted.

public MazePoint[][] readMaze(String fileToRead) throws IOException {

// TODO:

return maze;

}

This method takes in two parameters - a file name, and a 2-d array of MazePoint objects, which represents the expected array that the readMaze method should yield after reading the file. The function returns a boolean value - true if the expected array matches the array returned by readMaze, and false otherwise. If the test fails it should also print the expected maze and the actual maze returned by readMaze along with an error message.

public boolean testRead(String fileToRead, MazePoint[][] expected) throws IOException { return false; }

public class MazePoint { private char symbol; private char wall = 'X'; private char empty = '-'; private char path = '*'; public MazePoint(boolean isWall) { if (isWall) { this.symbol = this.wall; } else { this.symbol = this.empty; } } public boolean isWall() { return this.symbol == this.wall; }

public boolean isEmpty() { return this.symbol == this.empty; } public boolean isPath() { return this.symbol == this.path; }

public void setToPath() { this.symbol = this.path; }

public void setToEmpty() { this.symbol = this.empty; }

public void setToWall() { this.symbol = this.wall; }

public boolean symbolMatch(MazePoint other) { return other.symbol == this.symbol; }

public void printSymbol() { System.out.print(this.symbol); } }

Thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!