Java solution for solving a maze