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

Write a program that creates and displays a 10 by 10 maze. Here is an example of

ID: 3748771 • Letter: W

Question

Write a program that creates and displays a 10 by 10 maze. Here is an example of a maze display:

++++++++++

E +

++ +++ + + ++

+++++++ + ++

+++++++ ++

+++ +++ ++

+ E

++++++++++

++++++++++

This is just an example. Create a different maze for your program. Use this starter code:

public class DisplayMaze {

// represent elements of maze array with enumerated data type Values enum Values { space, wall, escape };

public static void main( String[] args ) {

// maze[][] stores walls, spaces, and exits of maze Values maze[][] = new Values[10][10];

// your code here

}

// initializes maze
public static void createMaze( Values maze[][] ) {

// your code here

}

// displays maze
public static void showMaze( Values maze[][] ) {

// your code here

}
} // end of DisplayMaze

Explanation / Answer

import java.util.Random;

public class DisplayMaze {

// represent elements of maze array with enumerated data type Values

enum Values{ space, wall, escape };

public static void main(String[] args) {

// maze[][] stores walls, spaces, and exits of maze

Values maze[][] = new Values[10][10];

// your code here

createMaze(maze);

showMaze(maze);

}

// initializes maze

public static void createMaze(Values maze[][]) {

// your code here

Random r = new Random();

for (int i = 0; i < 10; i++) {

for (int j = 0; j < 10; j++) {

int choice = r.nextInt(3);

switch (choice) {

case 0: //walls

maze[i][j] = Values.wall;

break;

case 1: // spaces

maze[i][j] = Values.space;

break;

case 2: //exits

maze[i][j] = Values.escape;

break;

default:

break;

}

}

}

}

// displays maze

public static void showMaze(Values maze[][]) {

// your code here

for (int i = 0; i < 10; i++) {

for (int j = 0; j < 10; j++) {

if(maze[i][j] == Values.space)

System.out.print(" ");

else if(maze[i][j] == Values.escape)

System.out.print("E ");

else if(maze[i][j] == Values.wall)

System.out.print("+ ");

}

System.out.println();

}

}

} // end of DisplayMaze

//output:

E + E E E + +
+ E + + E E + E
E + + E + E + E
+ E + E +
E + + E E E + E
+ + + +
E + + E + E E E +
E E + E +
E E + E E +
+ + E E E +

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