Conversation
Kotybamic
left a comment
There was a problem hiding this comment.
Took a look at the code and noticed some errors, check them out
| import java.io.FileReader; | ||
| import java.io.FileWriter; | ||
| import java.io.IOException; | ||
| import java.io.PrintWriter; |
There was a problem hiding this comment.
Checked every import using ctrl-f, this import is not used anywhere and is unnecessary clutter.
| import java.io.FileWriter; | ||
| import java.io.IOException; | ||
| import java.io.PrintWriter; | ||
| import java.io.UnsupportedEncodingException; |
There was a problem hiding this comment.
Similar clutter, this import is not utilized throughout the code
| Scanner inFile = new Scanner(new FileReader(filename)); | ||
|
|
||
| // Initialize array using first line of file -- size parameters | ||
| String arrSize = inFile.nextLine(); |
There was a problem hiding this comment.
should have some sort of catcher in the case that there is no next line, right now the program will crash if there is no next line
| int i = 0; | ||
| String rowData; | ||
| StringTokenizer st2; | ||
| while (inFile.hasNextLine()) { |
There was a problem hiding this comment.
theres no cap on this while loop, needs a check for i<m_rows to prevent it from going past the limit
| } | ||
|
|
||
| public Matrix add(Matrix m) {// add 'this' matrix to matrix m | ||
| Matrix newMat = new Matrix(this.m_rows, this.n_cols); |
There was a problem hiding this comment.
This function does not check the dimensions of the matrixes to make sure they can be added together to begin with
| Matrix id = new Matrix(squareSize, squareSize); | ||
|
|
||
| for (int i = 0; i < squareSize; i++) { | ||
| for (int j = 0; i < squareSize; i++) { |
There was a problem hiding this comment.
broken loop, incrementing the wrong variable should be j++
| } | ||
|
|
||
| public String toString() { | ||
| String result = ""; |
There was a problem hiding this comment.
Not really an error, this repeated concatenation will be inefficient when it comes to larger matrices
| } | ||
|
|
||
| public Matrix transpose() { | ||
| Matrix result = new Matrix(this.m_rows, this.n_cols); |
There was a problem hiding this comment.
This needs to be swapped, if you transpose a 2 by 3 matrix, the expected output should be 3 by 2
| this.arr = new double[m][n]; | ||
| for (int i = 0; i < this.m_rows; i++) { | ||
| for (int j = 0; j < this.n_cols; j++) { | ||
| this.arr[i][j] = 0; |
There was a problem hiding this comment.
There is absolutely no need for this. In Java, arrays are already initialized to 0.0
| return result; | ||
| } | ||
|
|
||
| public Matrix inverse() { |
There was a problem hiding this comment.
this might work for small matrixes, but even scaling a bit will result in a huge increase in processes, use a different method to get to the output we want
No description provided.