Question subject: Need help with Java Matrices using a Switch Statement
Posted: Tue Apr 06, 2010 5:56 am
Joined: Tue Apr 06, 2010 5:50 am Posts: 1 Has thanked: 0 time Have thanks: 0 time
my professor gave me this design document but i don't know where to start. if you can help me that would be great. i really do need as much help as i can possibly get. thanks. [:
Project #6 Design Document Matrix Arithmetic
Input Items 1. Data Type input I or D 2. Matrix Dimensions a. A (m, n) input m, input n b. B (j, k) input j, input k 3. Operation input op
a. int [ ] [ ] aIntMatrix; b. int [ ][ ] bIntMatrix; c. int [ ][ ] cIntMatrix; d. double [ ] [ ] aDblMatrix; e. double [ ][ ] bDblMatrix; f. double [ ][ ] cDblMatrix;
2. Create storage space for selected input matrices (dependent upon the data type and dimensions), e.g.,
Code:
a. int [ ] [ ] aIntMatrix = new int[m][n]; b. int [ ][ ] bIntMatrix = new int[j][k];
3. Create storage space for selected input matrices (dependent upon the data type, operation and dimensions), e.g.,
Code:
a. int [ ][ ] cIntMatrix = new int[m][k]; for op == “MULTIPLY” b. int [ ][ ] cIntMatrix = new int[m][n]; for op == “ADDITION” or “SUBTRACTION”
4. Populate the selected input arrays Computations
1. Main
Code:
If dataType is integer Switch(op) { Case + : { cIntMatrix = addMatrix(aIntMatrix, bIntMatrix); printMatrix(aIntMatrix); printMatrix(bIntMatrix); printMatrix(cIntMatrix); break; } Case - : { } Case * : { } Else Case + : { } Case - : { } Case * : { } } Switch(op) { }
2. Methods a. addMatrix
Code:
for(int i = 0; i < ... ; i++) for(int j = 0; j < ... ; j++) c[ i ][ j ] = a[ i ][ j ] + b[ i ][ j ];
b. subMatrix
Code:
for(int i = 0; i < ... ; i++) for(int j = 0; j < ... ; j++)
check dimensions for A (m, n) & B (j, k) check that m == j & n == k
Code:
c[ i ][ j ] = a[ i ][ j ] - b[ i ][ j ];
c. multMatrix
Code:
for(int k = 0; k < columns of c; k++) for(int i = 0; i < rows of b; i++) for(int j = 0; j < columns of a ; j++) c[ i ][ k ] = a[ i ][ j ] * b[ j ][ k ]
check dimensions for A (m, n) & B (j, k) check that & n == j