This is my first post on here so be gentle
public class SudokuApp
{
public static void main (String[] args) throws IOException
{
Scanner glaDOS = new Scanner (System.in);
System.out.print("PLEASE ENTER A VALID FILE NAME THAT CONTAINS A SUDOKU: ");
File sudokuFile = new File (glaDOS.next());
Scanner glaDOS2 = new Scanner (sudokuFile);
Sudoku puzzle = new Sudoku (glaDOS2);
System.out.println ("Unsolved: ");
System.out.println (puzzle);
System.out.println ("Solved: " );
System.out.println (puzzle);
System.out.println("Backtracking steps: ");
}
}
and my current code for the Sudoku class itself
public class Sudoku
{
//instance variables
private int row;
private int col;
private String numbers;
private char [][] puzzle;
/**
*
* @param sudokuReader the scanner containing the puzzle
* file to be read and scanned into an array
* @throws IOException
*
*/
public Sudoku (Scanner sudokuReader)
{
puzzle = new char [9][9];
for (int i = 0; i < 8; i++)
{
if(sudokuReader.hasNext())
{
numbers = sudokuReader.next();
for (int j = 0; j < 8; j++)
{
puzzle[row][col] = numbers.charAt(j);
}
}
}
System.out.println(puzzle[9][9]);
}
/**
* Method that checks to see if a number can be put in to
* a specific position on the Sudoku board
* @param row row position
* @param col column position
* @param num number being analyzed
* @return value stating if the move is legal
*/
public boolean isLegal (int row, int col, int num)
{
return true;
}
/**
* Methods that uses a backtracking algorithm to put
* numbers into positions on the puzzle and tries to
* solve it. If there is a solution, it returns true.
* If there is no solution, it returns false.
* @param row row position to start solving from
* @param col column position to start solving from
* @return value stating if puzzle can be solved
*/
public boolean solve (int row, int col, Sudoku puzzle)
{
// if(row++ == 8)
//return true;
//if (numbers.charAt(row, col) == '.')
//return(solve(row++, col++, puzzle));
//for(int = 1; i < 10; i++)
//{
//if(IsLegal(row, col, num))
//if(solve(row, col++, puzzle))
// return true;
//else
return false;
}
/**
* Returns a string representing the contents of the
* sudoku.
* @return
*/
public String ToString()
{
return "Unsolved: " + puzzle;
}
}
I am getting all sorts of weird errors right now. One of them I know is something to do with Eclipse which I am working on. The other one I get is:
StringOutOfBoundsException:
String index out of range: 1 (in java.lang.string)
whenever I run the code in BlueJ. I know it has something to do with how the data is being read in to the array but I'm not exactly sure what is...Also for the solve and IsLegal methods, I'm not sure whether I should have the Sudoku puzzle itself be a parameter or have the 2-D array being used be the parameter or what.... If anyone could please give me a little bit of direction and help with the troubles I'm having, I would greatly appreciate it. Thank you to all

New Topic/Question
Reply




MultiQuote





|