// MatrixTester.java
// File Revision Date: 09/02/08

package lab02;

public class MatrixTester {

  public static final int NROWS = 3;
  public static final int NCOLS = 5;

  // Range limits for random generation of int-valued matrix
  // components. All values will be in range MIN <= value < MAX:

  public static final int MIN = 0;
  public static final int MAX = 1000;

  private int [][] matrix;

  public MatrixTester () {
    matrix = new int [NROWS] [NCOLS];

    // Fill with random values...

    for (int row = 0; row < NROWS; row++) {
      for (int col = 0; col < NCOLS; col++) {
        matrix [row][col] = MIN + (int) (Math.random() * (MAX - MIN));
      }
    }
  }

  public void printAll () {
    System.out.println ();

    for (int row = 0; row < NROWS; row++) {
      for (int col = 0; col < NCOLS; col++) {
        System.out.print (matrix [row][col] + "\t");;
      }
      System.out.println ();	
    }

    System.out.println ();
  }    

  /**
   * Returns a 1D array of length NROWS, whose components represent
   * the sum of all the column values for each row.
   */
  public int [] rowSum () {
    int [] tempSum = new int [NROWS];

    // This is where you come in...

    return tempSum;
  }    

  /**
   * Returns a 1D array of length NCOLS, whose components represent
   * the sum of all the row values for each column.
   */
  public int [] colSum () {
    int [] tempSum = new int [NCOLS];

    // This is where you come in...

    return tempSum;
  }    

  public static void main (String [] args) {
    MatrixTester tester = new MatrixTester();
    tester.printAll();
    
    int [] rowSum = tester.rowSum();

    for (int r = 0; r < rowSum.length; r++) {
      System.out.print (rowSum[r] + "\t");
    }
    System.out.println();

    int [] colSum = tester.colSum();

    for (int c = 0; c < colSum.length; c++) {
      System.out.print (colSum[c] + "\t");
    }
    System.out.println();
  }
}
