uses unchecked or unsafe operations
Anyone have a clue whats going on here i keep getting unchecked or unsafe operations. Tried compiling it in command window. Still dont know what the problem is. Thanks.
import java.util.*;
// Class represents a Sudoku Grid
// This is the starting grid
// {4, 0, 0, 0, 0, 0, 3, 0, 8},
// {0, 0, 9, 1, 0, 7, 5, 0, 0},
// {2, 6, 0, 0, 5, 3, 1, 0, 0},
// {0, 0, 0, 0, 3, 6, 0, 8, 1},
// {0, 7, 0, 4, 0, 1, 0, 9, 0},
// {5, 1, 0, 7, 2, 0, 0, 0, 0},
// {0, 0, 5, 2, 9, 0, 0, 6, 7},
// {0, 0, 4, 6, 0, 8, 9, 0, 0},
// {8, 0, 6, 0, 0, 0, 0, 0, 2}
publicclass SuDokuGrid{
privatestaticfinalint GRSIZE = 9;// default grid size
privatefinalstaticint LCSIZE = 3;// large cell size
privateint[][][] grid;// sudoku grid
privateint size;// size of grid
private ArrayList undo;// list of moves
/**
* Default constructor creates standard 9x9 grid and sets in starting values
*/
public SuDokuGrid(){
this.size = GRSIZE;
//initialise the Grid
initGrid();
// set the starting conditions
addNumber(4, 0, 0);addNumber(3, 0, 6);addNumber(8, 0, 8);
addNumber(9, 1, 2);addNumber(1, 1, 3);addNumber(7, 1, 5);addNumber(5, 1, 6);
addNumber(2, 2, 0);addNumber(6, 2, 1);addNumber(5, 2, 4);addNumber(3, 2, 5);
addNumber(1, 2, 6);
addNumber(3, 3, 4);addNumber(6, 3, 5);addNumber(8, 3, 7);addNumber(1, 3, 8);
addNumber(7, 4, 1);addNumber(4, 4, 3);addNumber(1, 4, 5);addNumber(9, 4, 7);
addNumber(5, 5, 0);addNumber(1, 5, 1);addNumber(7, 5, 3);addNumber(2, 5, 4);
addNumber(5, 6, 2);addNumber(2, 6, 3);addNumber(9, 6, 4);addNumber(6, 6, 7);
addNumber(7, 6, 8);
addNumber(4, 7, 2);addNumber(6, 7, 3);addNumber(8, 7, 5);addNumber(9, 7, 6);
addNumber(8, 8, 0);addNumber(6, 8, 2);addNumber(2, 8, 8);
}// end constructor
/**
* Re-initialse the undo list. Initialise the Grid,
* resetting each cell to 0 and marking all numbers
* in each cell z-plane as available.
*/
publicvoid initGrid(){
undo =new ArrayList();
grid =newint[size][size][size + 1];
// initialse each cell
for (int r = 0; r < grid.length; r++){
for (int c = 0; c < grid[0].length; c++){
// top element of z-plane contains number in cell
grid[r][c][0] = 0;
// remaining elements of z-plane contain available
// numbers for cell
for (int z = 1; z < grid[0][0].length; z++){
grid[r][c][z] = z;
}
}
}
}
/**
* Utility method which determines if an undo move is possible
* @return - true if undo possible, false otherwise
*/
publicboolean undoPossible(){
return (undo.size() > 0);
}
/**
* Undo the last move, re-instating the grid to its last known state
* @return - return the move which was un-done
*/
public Move undo(){
Move move =null;
if (undo.size() > 0){
move = (Move) undo.remove(undo.size() - 1);
// reset grid cell to empty (0)
grid[move.r][move.c][0] = 0;
// restore other grid cell z-planes affected by this move
for (int i = 0; i < move.zplane.size(); i++){
Move z = (Move) move.zplane.get(i);
grid[z.r][z.c][z.n] = z.n;
}
}
return move;
}
/**
* Determine if a number is valid for a given cell z-plane
* @param n - number to verify
* @param zplane - cell zplane within which to verify number
* @return true if number is valid for cell, false otherwise
*/
privateboolean numberValid(int n,int[] zplane){
for (int i = 1; i < zplane.length; i++){
if (zplane[i] == n){
returntrue;
}
}
returnfalse;
}
/**
* Perform move - precondition row and column are valid
*
* @param n - number to play
* @param r - row in which to add numer
* @param c - column in which to add number
* @return true if move made otherwise false
* @throws Exception if grid coordinates are invalid
*/
publicboolean addNumber(int n,int r,int c){
boolean madeMove =false;
Move move =new Move(n, r, c);
// ensure number is valid for cell before adding
if (numberValid(n, grid[r][c])){
// add number to position 0 of z-plane contained at specified
// row/column
grid[r][c][0] = n;
madeMove =true;
// remove all occurances of n from each z-plane on this column
// and add changes to this moves z-plane
for (int cc = 0; cc < grid[0].length; cc++){
if (grid[r][cc][n] != 0){
grid[r][cc][n] = 0;
move.zplane.add(new Move(n, r, cc));
}
}
// remove all occurances of n from each z-plane on this row
for (int rr = 0; rr < grid.length; rr++){
if (grid[rr][c][n] != 0){
grid[rr][c][n] = 0;
move.zplane.add(new Move(n, rr, c));
}
}
// calculate origin cell of each large grid cell
int or = r - r % LCSIZE;
int oc = c - c % LCSIZE;
// remove all occurances of n from each z-plane in large grid cell
checkLargeGridCell(move, or, oc);
// add move to undo list
undo.add(move);
}
return madeMove;
}
/** check Large Grid Cell for cell z-planes affected by the move
*
* @param m - move being made
* @param or - large cell origin row
* @param oc - large cell origin column
*/
// move at the specified coordinates
privatevoid checkLargeGridCell(Move m,int or,int oc){
for (int r = or; r < or + LCSIZE; r++){
for (int c = oc; c < oc + LCSIZE; c++){
if (grid[r][c][m.n] != 0){
grid[r][c][m.n] = 0;
// add mofifications to
m.zplane.add(new Move(m.n, r, c));
}
}
}
}
// return Grid Cell
publicint getGridCell(int r,int c){
if (( r >= 0 && r < grid.length) &&
(c >= 0 && c < grid[0].length)){
return grid[r][c][0];
}else{
thrownew IndexOutOfBoundsException("invalid grid coordinates: " + r +"," + c);
}
}// end getGridCell
// return complete Grid
publicint [][] getGrid(){
int copy[][] =newint [grid.length][grid[0].length];
for (int r=0; r<copy.length; r++)
for (int c=0; c>< copy[0].length; c++)
copy[r][c] = grid[r][c][0];
return ( copy);
}// end getGrid
}// end SudokuGrid

