d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Javascript Project > Offering Fg If Necessary
Add Reply New Topic New Poll
Member
Posts: 1,781
Joined: Mar 16 2007
Gold: 0.00
Apr 25 2013 04:50pm
So I have a project to do and I'm completely lost on it

My only concern is for the class we work with a custom textbook and we have extra class paths added in so I'm not sure i'll get the help I need.

The project is here: http://www.cs.albany.edu/~sdc/CSI201/Spr13/Proj/Proj5/Proj5.pdf

There are two pre-written applications that need to be downloaded, and then have code added to them for the project to work. I'll give links to whoever wants them.
I can also send the extra class paths.

I can always get FG, so name your prices (Hopefully not too expensive ;) )
Member
Posts: 2,478
Joined: Jan 4 2007
Gold: 7,545.00
Apr 26 2013 06:09am
Fyi, this is Java not Javascript. Huge difference
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Apr 26 2013 09:53am
The CheckRow column works, but I wasn't able to test the rest cus it's a pain in the ass typing in all those numbers and i'm pretty busy at work right now. Let me know if it works. If not, I'll work on it some more.

And yea, this is Java, not Javascript

Code
import java.util.HashSet;
import java.util.Scanner;

public class Sudoku {
 static int board[][];

 public Sudoku( ) {
   board = new int[9][9];
 }

 public String toString( ) {
   String result = "";
   for ( int rowOfBlocks = 0; rowOfBlocks < 3; rowOfBlocks = rowOfBlocks + 1 ) {
     for ( int rowInABlock = 0; rowInABlock < 3; rowInABlock = rowInABlock + 1 ) {
       for ( int colOfBlocks = 0; colOfBlocks < 3; colOfBlocks = colOfBlocks + 1 ) {
         for ( int colInABlock = 0; colInABlock < 3; colInABlock = colInABlock + 1 ) {
           result = result
               + board[colOfBlocks * 3 + colInABlock][rowOfBlocks * 3
                   + rowInABlock] + " ";
         }
         result = result + " ";
       }
       result = result + "\n";
     }
     result = result + "\n";
   }
   return result;
 }

 public void read( Scanner scParam ) {
   for ( int rowOfBlocks = 0; rowOfBlocks < 3; rowOfBlocks = rowOfBlocks + 1 ) {
     for ( int rowInABlock = 0; rowInABlock < 3; rowInABlock = rowInABlock + 1 ) {
       for ( int colOfBlocks = 0; colOfBlocks < 3; colOfBlocks = colOfBlocks + 1 ) {
         for ( int colInABlock = 0; colInABlock < 3; colInABlock = colInABlock + 1 ) {
           board[colOfBlocks * 3 + colInABlock][rowOfBlocks * 3 + rowInABlock] = scParam.nextInt( );
         }
       }
     }
   }
 }

 public static boolean checkRow( int row ) {
   for ( int j = 0; j < 9; j++ )
     for ( int k = j + 1; k < 9; k++ )
       if ( k != j && board[k][row] == board[j][row] ) return false;
   return true;
 }

 public boolean checkColumn( int column ) {
   for ( int j = 0; j < 9; j++ )
     for ( int k = j + 1; k < 9; k++ )
       if ( k != j && board[column][k] == board[column][j] ) return false;
   return true;
 }

 public boolean checkBlock( int colOfBlocks, int rowOfBlocks ) {

   for ( int i = colOfBlocks; i < colOfBlocks + 3; i++ ) {
     HashSet<Integer> set = new HashSet<Integer>( );
     for ( int j = rowOfBlocks; j < rowOfBlocks + 3; j++ ) {
       if ( set.contains( board[j][i] ) ) return false;
       set.add( board[j][i] );
     }
   }
   return true;
 }

 public boolean checkAll( ) {
   for ( int i = 0; i < 9; i++ ) {
     if ( !checkRow( i ) ) {
       return false;
     }
     if ( !checkColumn( i ) ) {
       return false;
     }
   }
   return true;
 }

 public static void main( String[] a ) {

   Scanner s = new Scanner( System.in );
   Sudoku sudokuRef = new Sudoku( );
   sudokuRef.read( s );
   System.out.print( sudokuRef );

 }
}
Member
Posts: 1,781
Joined: Mar 16 2007
Gold: 0.00
Apr 26 2013 11:29am
Quote (labatymo @ Apr 26 2013 10:53am)
The CheckRow column works, but I wasn't able to test the rest cus it's a pain in the ass typing in all those numbers and i'm pretty busy at work right now. Let me know if it works. If not, I'll work on it some more.

And yea, this is Java, not Javascript

Code
import java.util.HashSet;
import java.util.Scanner;

public class Sudoku {
 static int board[][];

 public Sudoku( ) {
   board = new int[9][9];
 }

 public String toString( ) {
   String result = "";
   for ( int rowOfBlocks = 0; rowOfBlocks < 3; rowOfBlocks = rowOfBlocks + 1 ) {
     for ( int rowInABlock = 0; rowInABlock < 3; rowInABlock = rowInABlock + 1 ) {
       for ( int colOfBlocks = 0; colOfBlocks < 3; colOfBlocks = colOfBlocks + 1 ) {
         for ( int colInABlock = 0; colInABlock < 3; colInABlock = colInABlock + 1 ) {
           result = result
               + board[colOfBlocks * 3 + colInABlock][rowOfBlocks * 3
                   + rowInABlock] + " ";
         }
         result = result + " ";
       }
       result = result + "\n";
     }
     result = result + "\n";
   }
   return result;
 }

 public void read( Scanner scParam ) {
   for ( int rowOfBlocks = 0; rowOfBlocks < 3; rowOfBlocks = rowOfBlocks + 1 ) {
     for ( int rowInABlock = 0; rowInABlock < 3; rowInABlock = rowInABlock + 1 ) {
       for ( int colOfBlocks = 0; colOfBlocks < 3; colOfBlocks = colOfBlocks + 1 ) {
         for ( int colInABlock = 0; colInABlock < 3; colInABlock = colInABlock + 1 ) {
           board[colOfBlocks * 3 + colInABlock][rowOfBlocks * 3 + rowInABlock] = scParam.nextInt( );
         }
       }
     }
   }
 }

 public static boolean checkRow( int row ) {
   for ( int j = 0; j < 9; j++ )
     for ( int k = j + 1; k < 9; k++ )
       if ( k != j && board[k][row] == board[j][row] ) return false;
   return true;
 }

 public boolean checkColumn( int column ) {
   for ( int j = 0; j < 9; j++ )
     for ( int k = j + 1; k < 9; k++ )
       if ( k != j && board[column][k] == board[column][j] ) return false;
   return true;
 }

 public boolean checkBlock( int colOfBlocks, int rowOfBlocks ) {

   for ( int i = colOfBlocks; i < colOfBlocks + 3; i++ ) {
     HashSet<Integer> set = new HashSet<Integer>( );
     for ( int j = rowOfBlocks; j < rowOfBlocks + 3; j++ ) {
       if ( set.contains( board[j][i] ) ) return false;
       set.add( board[j][i] );
     }
   }
   return true;
 }

 public boolean checkAll( ) {
   for ( int i = 0; i < 9; i++ ) {
     if ( !checkRow( i ) ) {
       return false;
     }
     if ( !checkColumn( i ) ) {
       return false;
     }
   }
   return true;
 }

 public static void main( String[] a ) {

   Scanner s = new Scanner( System.in );
   Sudoku sudokuRef = new Sudoku( );
   sudokuRef.read( s );
   System.out.print( sudokuRef );

 }
}



Thank you very much. I'm waiting to hear back from my professor on a question about the project and then I'll be able to tell you how it runs.
I did run into a compiler issue though, that HashSet cannot be resolved to a type. He's never mentioned HashSet in lecture so I'm not sure what to do.
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Apr 26 2013 11:34am
I'll change the code so it doesn't use a HashSet. Your professor will probably be suspicious if he sees a HashSet and you haven't learned about them yet lol
Member
Posts: 1,781
Joined: Mar 16 2007
Gold: 0.00
Apr 26 2013 01:09pm
For testing purposes I deleted the class with the HashSet to see if the other classes work.

I found out he gave us a board to test on (at least I think that's what it's for lol): http://www.cs.albany.edu/~sdc/CSI201/Spr13/Proj/Proj5/Shortz301.txt

I compiled/ran it and it returned true, which i assume means it worked.

If it returns true, what is the point of having the check9Array method? this whole project is confusing to me and my professor never really did a great job explaining it.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll