I have a method that should return a enum, however I am not to sure how to code this (it is a activity from my paper). Below is the method (in the class called Maze):
private MazeStatus[][] stringToMaze(String sMaze) {
String[] splitString = sMaze.split("\n");
char[][] array = new char[splitString.length][];
MazeStatus[][] mazeStat;
for (int x = 0; x < splitString.length; x++) {
array[x] = new char[splitString[x].length()];
array[x] = splitString[x].toCharArray();
for (int y = 0; y < splitString[x].length(); y++) {
switch (array[x][y]) {
case '.':
mazeStat[x][y] = MazeStatus.VISITED;
break;
}
}
}
return null; // TO DO (Part 1): change appropriately
}
Here is the MazeStatus
class:
public enum MazeStatus {
OPEN(' '), OBSTACLE('#'), GOAL('x'), VISITED('.');
private char text;
MazeStatus(char s) {
this.text = s;
}
public char text() {
return this.text;
}
}
In the method I have tried creating a enum
MazeStatus[][] mazeStat;
and adding values to it:
mazeStat[x][y] = MazeStatus.VISITED;
But of course it complains about it not being initialized. I do not know how to initialize a enum, especially a bidimensional array enum, without creating the actual Maze object.