Given files code below: ONLY MyMaze.java should be updated, the others are just helper code and interfaces.
Cell.java
/*
A Maze is made up of Cells
*/
public class Cell {
private boolean visited; // whether the cell has been visited (true if visited, false if not visited)
private boolean right; // whether the cell has a right border (true if a right boundary, false if an open right)
private boolean bottom; // whether the cell has a bottom border (true if a bottom boundary, false if an open bottom)
// All cells are initialized to full walls
public Cell(){
visited = false;
right = true;
bottom = true;
}
/**********
* Setter functions
**********/
public void setVisited(boolean visited) { this.visited = visited; }
public void setRight(boolean right) { this.right = right; }
public void setBottom(boolean bottom) { this.bottom = bottom; }
/**********
* Getter functions
**********/
public boolean getVisited() { return visited; }
public boolean getRight() { return right; }
public boolean getBottom() { return bottom; }
}
MyMaze.java
import java.util.Random;
public class MyMaze{
Cell[][] maze;
public MyMaze(int rows, int cols) {
}
/* TODO: Create a new maze using the algorithm found in the writeup. */
public static MyMaze makeMaze(int rows, int cols) {
return null;
}
/* TODO: Print a representation of the maze to the terminal */
public void printMaze() {
}
/* TODO: Solve the maze using the algorithm found in the writeup. */
public void solveMaze() {
}
public static void main(String[] args){
/* Any testing can be put in this main function */
}
}
NGen.java
// NGen.java
// A *simplified* generic node class for use with the Stack1Gen class
// and other data structures as desired; uses generics for the data
public class NGen {
// constructors
public NGen () {}
public NGen (T o, NGen link) {
data = o;
next = link;
}
// selectors
public T getData() {
return data;
}
public void setData(T o) {
data = o;
}
public NGen getNext() {
return next;
}
public void setNext(NGen link) {
next = link;
}
// instance variables
private T data;
private NGen next;
} // NGen class
Q1Gen.java
// Q1Gen.java
// Generic queue implementation using a linked list of nodes (see NGen.java)
public class Q1Gen implements QGen {
// constructor
public Q1Gen () {}
// selectors
public void add(T o) {
if (size == 0) {
front = new NGen (o, null);
rear = front;
}
else {
rear.setNext(new NGen (o, null));
rear = rear.getNext();
}
size++;
}
public T remove() {
T answer;
if (size == 0)
return null;
answer = front.getData();
front = front.getNext();
size--;
if (size == 0)
rear = null;
return answer;
}
public int length() {
return size;
}
public boolean isEmpty() { return size == 0; }
private int size;
private NGen front;
private NGen rear;
} // Q1Gen class
QGen.java
// QGen.java
// Queue Interface for a generic queue
public interface QGen {
void add(T o);
/* adds an object o to a queue placing it in the order of arrival
relative to other items added to the queue--first in, first out
(FIFO) */
T remove();
/* removes and returns the object placed in a queue prior
to any other items presently in the queue */
int length();
/* returns the integer quantity of items currently present in the
queue */
} // QGen Interface
Stack1Gen.java
// Stack1Gen.java
// The StackGen Interface is implemented using a linked list
// The linked list used is a simple generic node class called NGen. (See NGen.java)
public class Stack1Gen implements StackGen {
// constructor
public Stack1Gen () {}
// selectors
public void push(T o) {
start = new NGen (o, start);
}
public T pop() {
if (start == null)
throw new RuntimeException("Tried to pop an empty stack");
else {
T data = start.getData();
start = start.getNext();
return data;
}
}
public T top() {
if (start == null)
return null;
else return start.getData();
}
public boolean isEmpty() {
if (start == null)
return true;
else return false;
}
// instance variables
private NGen start = null;
} // Stack1Gen class
StackGen.java
// StackGen.java
// A Possible Generic Stack Interface
// Identify the methods as absolutely necssary, nice to have,
// or redundant
public interface StackGen {
// Interface for a Generic Stack
public void push(T o);
/* adds an object o to the top of a stack by placing it in the
reverse order of arrival relative to other items added to the
stack; that is, last in, first out (LIFO) */
public T pop();
/* removes and returns the object placed in a stack most recentlt
relative to any other items presently in the stack */
public T top();
/* returns the Object placed in a stack most recently, or null
if the stack contains no items */
public boolean isEmpty();
/* returns true when a stack currently contains no items, false
otherwise */
} // StackGen Interface