Question: trying to read a file(2d array with row and column number at the first 2 numbers) for example 3 3 - - X X -

trying to read a file(2d array with row and column number at the first 2 numbers) for example

3 3 - - X X - - X X -

my code

public MazePoint[][] readMaze(String fileToRead) throws IOException { FileInputStream fileByteStream = null; // File input stream Scanner inFS= null; // Scanner object fileByteStream = new FileInputStream(fileToRead); inFS= new Scanner(fileByteStream); int size = inFS.nextInt(); MazePoint[][] maze = new MazePoint[size][size]; while(inFS.hasNext()) { for (int row = 0; row < size; row++) { for (int column = 0; column < size; column++) { maze[row][column] = inFS.nextInt(); } } } return maze; }

error: Type mismatch: cannot convert from int to MazePoint

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); } }

How to fix it? thank you

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!