2014-11-19 HW

posted Nov 18, 2014, 5:32 PM by Samuel Konstantinovich   [ updated Nov 19, 2014, 8:21 AM ]
Reminder: Exam Friday.

Word search design today. 

Goal: Word Search basics.
-Design a data structure to hold the words.
-Decide on how the overall program would work.
-Decide on how to start writing this program.
-Implement the first method, and a way to test it.

Classwork + Homework:
1. You will make a new github folder 03wordsearch. You will write all of your code there, commit and push regularly. I expect to see the commits whenever you have lab time, and whenever you have "homework" to work on this.

2. You will check your git commits, and if you see your commits do NOT have your icon that means your email address is not set on your local account. Fix this! If you don't know what this means, or how to fix, ask someone. 

3. You can start to comment in Javadoc style, and create cool docs by using:
javadoc *.java -d folderName
This will create javadocs for all of the java files in the current directory. It will place the html files in a subdirectory called folderName. Do not add/commit your docs. Do not name your subdirectory folderName, I suggest docs.

4. Base code for the word grid. 

public class WordGrid{
    private char[][]data;

    /**Initialize the grid to the size specified and fill all of the positions
     *with spaces.
     *@param row is the starting height of the WordGrid
     *@param col is the starting width of the WordGrid
     */
    public WordGrid(int rows,int cols){
    }

    /**Set all values in the WordGrid to spaces ' '*/
    private void clear(){
    }

    /**The proper formatting for a WordGrid is created in the toString.
     *@return a String with each character separated by spaces, and each row
     *separated by newlines.
     */
    public String toString(){
    }

    /**Attempts to add a given word to the specified position of the WordGrid.
     *The word is added from left to right, must fit on the WordGrid, and must
     *have a corresponding letter to match any letters that it overlaps.
     *
     *@param word is any text to be added to the word grid.
     *@param row is the vertical locaiton of where you want the word to start.
     *@param col is the horizontal location of where you want the word to start.
     *@return true when the word is added successfully. When the word doesn't fit,
     *or there are overlapping letters that do not match, then false is returned.
     */
    public boolean addWordHorizontal(String word,int row, int col){
    }

    //vertical + diagonal should be implemented as well.

}


If you worry that you want to do better, then you can practice on some other methods: (optional) 

Easy:
public static int max(int[][] ary
   returns the maximum value in the 2d parameter array ary.

public static int rowSum(int[][] ary, int x)
   returns the sum of the elements in Row x of AR. 

public static boolean isSquare(int[][] AR)
   checks if the array is square (i.e. every row has the same length as AR itself).

Moderate:

public static int[] allRowSums(int[][] AR)
   calculates the row sum for every row and returns each of the values in an array. Index i of the return array contains the sum of elements in row i.

public static int columnSum(int[][] AR, int x)
   returns the sum of the elements in Column x of AR (careful with rows of different lengths!).

public static boolean isRowMagic(int[][] AR)
   checks if the array is row-magic (this means that every row has the same row sum).

public static boolean isColumnMagic(int[][] AR)
   checks if the array is column-magic (this means that every column has the same column sum).


Comments