/*********************************************************************
 * Implements a 2-D array of characters
 * 
 * @author arch
 * @version Jan 23, 2014
 * 
 ********************************************************************/
public class CharMatrix
{
    /**************************************************************************************** 
     * theArray Holds the array that represents the game board.
     ***************************************************************************************/
    private char[][] theArray;

    /******************************************************************************************
     * Constructor: creates a grid with dimensions rows, cols, and fills it with spaces
     * 
     * @param rows
     *            Rows in array
     * @param cols
     *            Columns in array
     *****************************************************************************************/
    public CharMatrix(int rows, int cols)
    {
        // ================================================
        // This one is written for you. Notice how it uses
        // the other constructor to do all the work.
        // =================================================
        this(rows, cols, ' ');
    }

    /******************************************************************************************
     * Constructor: creates a grid with dimensions rows , cols , and fills it with the fill
     * character.
     * 
     * @param rows
     *            Rows in array
     * @param cols
     *            Cols in array
     * @param fill
     *            Character to put into array
     *****************************************************************************************/
    public CharMatrix(int rows, int cols, char fill)
    {
        // Stub

        // ===========================================================================
        // Hint, you need to instantiate the 2D array, then populate it. And just like
        // the previous constructor used this constructor to do its work for it, this
        // method can use the "fillRect" method to do all the work of populating the array.
        // ============================================================================
    }

    /******************************************************************************************
     * Fills the given rectangle with the fill characters. row0, col0 is the upper left corner
     * and row1, col1 is the lower right corner of the rectangle.
     * 
     * @param row0
     *            Upper left row
     * @param col0
     *            Upper left column
     * @param row1
     *            Lower right row
     * @param col1
     *            Lower right column
     * @param fill
     *            Character to put into array
     *****************************************************************************************/
    public void fillRect(int row0, int col0, int row1, int col1, char fill)
    {
        // Stub

        // =============================================================================
        // Below are two "debugging statement that you can temporarily uncomment
        // if it helps in debugging.
        // =============================================================================
        // System.out.printf("FillRect %dx%d %dx%d '%c':\n", row0, col0, row1, col1, fill);
        // System.out.printf("%s\n", this.toString());
    }

    /******************************************************************************************
     * Fills the given rectangle with the SPACE character. row0, col0 is the upper left corner
     * and row1, col1 is the lower right corner of the rectangle.
     * 
     * @param row0
     *            Upper left row
     * @param col0
     *            Upper left column
     * @param row1
     *            Lower right row
     * @param col1
     *            Lower right column
     * @param fill
     *            Character to put into array
     *****************************************************************************************/
    public void clearRect(int row0, int col0, int row1, int col1)
    {
        // ================================================
        // This one is written for you. Notice how it uses
        // "fillRect" to do all the work.
        // =================================================
        this.fillRect(row0, col0, row1, col1, ' ');
    }

    /******************************************************************************************
     * Accessor that returns the number of rows in the array.
     * 
     * @return The number of rows in the array.
     *****************************************************************************************/
    public int numRows()
    {
        return -1; // Stub
    }

    /******************************************************************************************
     * Accessor that returns the number of columns in the array.
     * 
     * @return The number of columns in the array.
     *****************************************************************************************/

    public int numCols()
    {
        return -1; // Stub
    }

    /*********************************************************************
     * Method that returns true if the character at row, col is a SPACE, false otherwise
     * 
     * @param row
     *            The row
     * @param col
     *            The col
     * @return True if the character is a SPACE, false otherwise
     ********************************************************************/
    public boolean isEmpty(int row, int col)
    {
        return false; // Stub
    }

    /*********************************************************************
     * A method that returns the count of all non-SPACE characters in the row.
     * 
     * @param row
     *            The row
     * @return The count of all non-SPACE characters in row.
     ********************************************************************/
    public int countInRow(int row)
    {
        return -1; // Stub
    }

    /*********************************************************************
     * A method that returns the count of all non-SPACE characters in the column.
     * 
     * @param col
     *            The column
     * @return The count of all non-SPACE characters in the column
     ********************************************************************/
    public int countInCol(int col)
    {
        return -1; // Stub
    }

    /***************************************************************
     * A method that returns a string representation of the object.
     * 
     * @return The string representation of the object
     ***************************************************************/
    public String toString()
    {
        String arrayStr = "";
        
        for (int row = 0; row < this.numRows(); row++)
        {
            arrayStr += "[";
            for (int col = 0; col < this.numCols(); col++)
                arrayStr += this.theArray[row][col];
            arrayStr += "]\n";
        }
        return arrayStr;
    }
}
