Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Java Matrices using a Switch Statement

Tue Apr 06, 2010 5:56 am

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

Allocations & Populations
1. Create reference variables
Code:
     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



Post a reply
  Related Posts  to : Java Matrices using a Switch Statement
 java switch example     -  
 difference between break statement and a continue statement     -  
 difference between a while statement and a do statement     -  
 Switch vs Hub     -  
 php switch     -  
 JavaScript switch example     -  
 Use Switch with strings     -  
 network switch     -  
 switch command for string value     -  
 switch keyword in c++ usage     -