CIS 1068: Homework 9

Handed out: 03/23/10
Due: by 1:00pm on 03/29/10
Email program to TA

Your program consists of a class, Lab9. It will be invoked with the command
java Lab9 n
where n is a positive integer, something like 5, or 6, or 7, or 8,..
The main program will

  1. Create an nxn matrix and fill it as follows: the first row will contain 0,1,2,..,n-1; the second row will contain n, n+1, n+2, .., 2*n-1; ..; and so on. It will then print this matrix, one row per line.
  2. Invoke a method transpose that, given a square matrix, it transposes it around the main diagonal. It will then print out the resulting matrix.
  3. Invoke a method transpose2 that, given a square matrix, it transposes it around the secondary diagonal. It will then print out the resulting matrix.
  4. For each element in the array, invoke a method neighborhood that, given a square matrix, and the row and column of an element in the matrix, prints out the complete neighborhood of that element (North West neighbor, North neighbor, North East neighbor, West neighbor, element itself, East neighbor, South West neighbor, South neighbor, South East neighbor).
For example, if the original matrix is
    0   1   2   3   4
    5   6   7   8   9
   10  11  12  13  14
   15  16  17  18  19
   20  21  22  23  24
the transpose matrix is
   0   5  10  15  20
   1   6  11  16  21
   2   7  12  17  22
   3   8  13  18  23
   4   9  14  19  24
the transpose2 matrix is
   24 19 14  9  4
   23 18 13  8  3
   22 17 12  7  2
   21 16 11  6  1
   20 15 10  5  0
and the neighborhoods are
   0  1  5  6
   0  1  2  5  6  7
   1  2  3  6  7  8
   2  3  4  7  8  9
   3  4  8  9
   0  1  5  6 10 11
   0  1  2  5  6  7 10 11 12
   .....
   18  19 23 24

Send to the TA a case analysis for this problem: problem statement, analysis, design, implementation, and testing.