0

I am working on this project to solve a maze using a queue in Java. As I was working on the main class, I am getting errors specically in the enqueue and dequeue methods.

public void mazeSolver(int startRow, int startCol, int endRow, int endCol) { 
    Location location = new Location();
    location.setPosition(startRow, startCol);
    LocationQueue queue = new LocationQueue();
    queue.enqueue(location);
    while (!queue.isEmpty()) {
        location = queue.dequeue();
        mazeArray[location.getRow()][location.getColumn()] = '.';
        if ((location.getRow() == endRow && location.getColumn() == endCol)) {
            break;
        }
        if (location.getRow() + 1 < Rows) {
            if (mazeArray[location.getRow() + 1][location.getColumn()] == ' ') {
                Location newLocation = new Location();
                newLocation.setPosition(location.getRow() + 1, location.getColumn());
                queue.enqueue(newLocation);
            }
        }
        if (location.getRow() - 1 >= 0) {
            if (mazeArray[location.getRow() - 1][location.getColumn()] == ' ') {
                Location newLocation = new Location();
                newLocation.setPosition(location.getRow() - 1, location.getColumn());
                queue.enqueue(newLocation);
            }
        }
        if (location.getColumn() + 1 < Columns) {
            if (mazeArray[location.getRow()][location.getColumn() + 1] == ' ') {
                Location newLocation = new Location();
                newLocation.setPosition(location.getRow(), location.getColumn() + 1);
                queue.enqueue(newLocation);
            }
        }
        if (location.getColumn() - 1 > 0) {
            if (mazeArray[location.getRow()][location.getColumn() - 1] == ' ') {
                Location newLocation = new Location();
                newLocation.setPosition(location.getRow(), location.getColumn() - 1);
                queue.enqueue(newLocation);
            }
        }
    }
}

I have a LocationQueue class which involves the enqueue and dequeue methods:

public class LocationQueue<Location> {

LinkList locationList = new LinkList();

public void enqueue(int iData) {
    locationList.addLast(iData);
}

public Node dequeue() {
    if (!locationList.isEmpty()) {
        return locationList.deleteFirst();
    } else {
        return null;
    }
}

public void displayQueue() {
    locationList.displayList();
    System.out.println();
}

public boolean isEmpty() {
    return locationList.isEmpty();
}
}

And this is my Node class:

public class Node  {
int iData;
Node next;

public Node (int values) {
    iData = values;
    next = null;
}

  public void displayNode(){
        System.out.print(iData + " ");
    }
}

This issue may be a simple fix and I haven't catch where I'm doing it wrong. Since the error is stating "The method enqueue(int) in the type LocationQueue is not applicable for the arguments (Location)" and "Type mismatch: cannot convert from Node to Location". I'm just unsure what section of the code I need to change. My Location and LinkList class may be irrelevant to post in this issue, however if you would like to see both classes I wouldn't mind posting it.

Note: If my format of the code looks a bit off, my apologies. I'm still getting used to formatting the code on StackOverflow.

Alice
  • 25
  • 5
  • Seems pretty self-explanatory. You're trying to pass a `Location` to a method that expects `int`. – shmosel Apr 11 '19 at 02:52
  • I noticed the int type appearing in the LocationQueue class, but I'm not sure what to change it to make the method pass a Location. In my Location class, I just have getRow, getColumn, and setPosition so they don't really help in this case – Alice Apr 11 '19 at 03:12

0 Answers0