Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java programming MAZE Project This project has 3 sections: Maze class Command Li

ID: 3606605 • Letter: J

Question

Java programming

MAZE Project

This project has 3 sections:

Maze class

Command Line program

GUI that uses Maze Class

Please be creative. You should work as groups: Small group with 2-3 students.

Rubric:

Compiles without error (with any maze): 10 points

Runs without error (with any maze): 10 points

Logic: 20%

Java Programming Standards: 20%

Organizations: 15%

Proper Comments: 5%

Display: 10%

Presentation: 10%

1) Write a Maze class with the following requirements:

Takes any two-dimensional array that represents a maze: 0s (zeros) for the walls, and 1s for the available paths.

There will be only one constructor that takes a two-dimensional array

A method named “displayMaze” should print the maze (bird-view) that shows the walls and the available paths, and the path taken so far (if any)

A method named “takeStep” that takes one step each time when it is called and displays the maze again. Use the algorithm that checks right turn first. And keeps checking counter-clockwise until finds a path.

A method named “findExit” runs and finds the solution all the way to the exit and displays the maze showing the suggested path

Assume that entry point of the maze is always the first row (row 0) and the third column (column 2) and the first move direction is south.

Test program is given for your testing

The program should work with any Maze including different size of maze.

Explanation / Answer

Code:

public class Main {

public char[][] maze =

{{'*',' ','*','*','*','*','*','*','*'},

{'*',' ',' ',' ',' ',' ','*',' ','*'},

{'*',' ','*','*','*','*','*',' ','*'},

{'*',' ','*',' ','*',' ',' ',' ','*'},

{'*',' ','*',' ','*','*','*',' ','*'},

{'*',' ',' ',' ','*',' ',' ',' ','*'},

{'*','*','*',' ','*',' ','*',' ','*'},

{'*','*','*',' ',' ',' ','*',' ','*'},

{'*','*','*','*','*','*','*',' ','*'}

};

public void solveMaze(int x, int y) {

if (takeStep(x,y)) {

maze[x][y] = 'S';

}

}

public boolean takeStep (int x, int y) {

if (maze[x][y] == 'E') {

return true;

}

if (maze[x][y] == '*' || maze[x][y] == '#') {

return false;

}

maze[x][y] = '#';

boolean result;

result = takeStep(x, y+1);

if (result) { return true;}

result = takeStep(x-1, y);

if (result) { return true;}

result = takeStep(x, y-1);

if (result) { return true;}

result = takeStep(x+1, y);

if (result) { return true;}

maze[x][y] = ' ';

return false;

}

public String toString() {

String output = "";

for (int x=0; x<9; x++) {

for (int y=0; y<9; y++) {

output += maze[x][y] + " ";

}

output += " ";

}

return output;

}

public static void main(String[] args) {

Main m = new Main();

m.maze[0][1] = 'E';

m.solveMaze(8,7);

System.out.println(m);

}

}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote