Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

This is a public method (I'm calling it addMatrix()) that has only one parameter for a DoubleMatrix to add this doubMatrix (not changing this doubMatrix) and the parameter's doubMatrix and return a new DoubleMatrix (you'll need a local 2-dim. array to store the result of adding and pass to the constructor).

Make sure you check if the dimensions of this doubMatrix and the parameter's doubMatrix are the same (if not, return a new DoubleMatrix calling the first constructor passing 1, 1).

package homework3;
public class DoubleMatrix
{
 private double[][] doubMatrix;
 public DoubleMatrix()
 {
 int row;
 int col;
 if(row > 0 && col > 0)
 {
 makeDoubMatrix(1,1);
 }
 else
 {
 row = 1;
 col = 1;
 }
 }
 
 public DoubleMatrix(double[][] tempArray) 
 {
 if(tempArray != null)
 {
 for(int i = 0; i < tempArray.length-1;i++)
 {
 if(tempArray[i].length == tempArray[i+1].length)
 {
 doubMatrix = tempArray;
 }
 }
 }
 else
 {
 makeDoubMatrix(1,1);
 }
 }
 
 public int getDim1()
 {
 return doubMatrix.length;
 }
 
 public int getDim2()
 {
 return doubMatrix[0].length;
 }
 
 private void makeDoubMatrix(int row, int col)
 {
 double[][] tempArray = new double[row][col];
 for(int i = 0;i < tempArray.length;i++)
 for(int j = 0;j < tempArray[i].length;j++)
 {
 tempArray[i][j] = Math.random() * (100); 
 } //end for 
 tempArray = doubMatrix;
 }
 
 public double[][] addMatrix(double[][] doubMatrix)
 { 
 this. doubMatrix = doubMatrix;
 double[][] tempArray = null;
 if(this.doubMatrix.length == doubMatrix.length)
 if(this.doubMatrix[0].length == doubMatrix[0].length)
 {
 for(int i = 0; i< this.doubMatrix.length;i++)
 for(int j = 0; j< this.doubMatrix[i].length;j++ )
 {
 tempArray[i][j] = this.doubMatrix[i][j] + doubMatrix[i][j];// add two matrices 
 }//end for 
 }
 else
 {
 return tempArray = new double[1][1];
 }
 
 return tempArray;
 }
}

This is a public method (I'm calling it addMatrix()) that has only one parameter for a DoubleMatrix to add this doubMatrix (not changing this doubMatrix) and the parameter's doubMatrix and return a new DoubleMatrix (you'll need a local 2-dim. array to store the result of adding and pass to the constructor).

Make sure you check if the dimensions of this doubMatrix and the parameter's doubMatrix are the same (if not, return a new DoubleMatrix calling the first constructor passing 1, 1).

package homework3;
public class DoubleMatrix
{
 private double[][] doubMatrix;
 public DoubleMatrix()
 {
 int row;
 int col;
 if(row > 0 && col > 0)
 {
 makeDoubMatrix(1,1);
 }
 else
 {
 row = 1;
 col = 1;
 }
 }
 
 public DoubleMatrix(double[][] tempArray) 
 {
 if(tempArray != null)
 {
 for(int i = 0; i < tempArray.length-1;i++)
 {
 if(tempArray[i].length == tempArray[i+1].length)
 {
 doubMatrix = tempArray;
 }
 }
 }
 else
 {
 makeDoubMatrix(1,1);
 }
 }
 
 public int getDim1()
 {
 return doubMatrix.length;
 }
 
 public int getDim2()
 {
 return doubMatrix[0].length;
 }
 
 private void makeDoubMatrix(int row, int col)
 {
 double[][] tempArray = new double[row][col];
 for(int i = 0;i < tempArray.length;i++)
 for(int j = 0;j < tempArray[i].length;j++)
 {
 tempArray[i][j] = Math.random() * (100); 
 } //end for 
 tempArray = doubMatrix;
 }
 
 public double[][] addMatrix(double[][] doubMatrix)
 { 
 this. doubMatrix = doubMatrix;
 double[][] tempArray = null;
 if(this.doubMatrix.length == doubMatrix.length)
 if(this.doubMatrix[0].length == doubMatrix[0].length)
 {
 for(int i = 0; i< this.doubMatrix.length;i++)
 for(int j = 0; j< this.doubMatrix[i].length;j++ )
 {
 tempArray[i][j] = this.doubMatrix[i][j] + doubMatrix[i][j];// add two matrices 
 }//end for 
 }
 else
 {
 return tempArray = new double[1][1];
 }
 
 return tempArray;
 }
}

This is a public method (I'm calling it addMatrix()) that has only one parameter for a DoubleMatrix to add this doubMatrix (not changing this doubMatrix) and the parameter's doubMatrix and return a new DoubleMatrix (you'll need a local 2-dim. array to store the result of adding and pass to the constructor).

Make sure you check if the dimensions of this doubMatrix and the parameter's doubMatrix are the same (if not, return a new DoubleMatrix calling the first constructor passing 1, 1).

package homework3;
public class DoubleMatrix
{
 private double[][] doubMatrix;
 public DoubleMatrix()
 {
 int row;
 int col;
 if(row > 0 && col > 0)
 {
 makeDoubMatrix(1,1);
 }
 else
 {
 row = 1;
 col = 1;
 }
 }
 
 public DoubleMatrix(double[][] tempArray) 
 {
 if(tempArray != null)
 {
 for(int i = 0; i < tempArray.length-1;i++)
 {
 if(tempArray[i].length == tempArray[i+1].length)
 {
 doubMatrix = tempArray;
 }
 }
 }
 else
 {
 makeDoubMatrix(1,1);
 }
 }
 
 public int getDim1()
 {
 return doubMatrix.length;
 }
 
 public int getDim2()
 {
 return doubMatrix[0].length;
 }
 
 private void makeDoubMatrix(int row, int col)
 {
 double[][] tempArray = new double[row][col];
 for(int i = 0;i < tempArray.length;i++)
 for(int j = 0;j < tempArray[i].length;j++)
 {
 tempArray[i][j] = Math.random() * (100); 
 } //end for 
 tempArray = doubMatrix;
 }
 
 public double[][] addMatrix(double[][] doubMatrix)
 { 
 this. doubMatrix = doubMatrix;
 double[][] tempArray = null;
 if(this.doubMatrix.length == doubMatrix.length)
 if(this.doubMatrix[0].length == doubMatrix[0].length)
 {
 for(int i = 0; i< this.doubMatrix.length;i++)
 for(int j = 0; j< this.doubMatrix[i].length;j++ )
 {
 tempArray[i][j] = this.doubMatrix[i][j] + doubMatrix[i][j];// add two matrices 
 }//end for 
 }
 else
 {
 return tempArray = new double[1][1];
 }
 
 return tempArray;
 }
}
edited tags
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
added 2 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

add Matrix addMatrix() method review

Can anyone review my addMatrix() method to see if I am following the instructions correctly?

These are the instructions:

This is a public method (I'm calling it addMatrix()) that has only one parameter for a DoubleMatrix to add this doubMatrix (not changing this doubMatrix) and the parameter's doubMatrix and return a new DoubleMatrix (you'll need a local 2-dim. array to store the result of adding and pass to the constructor).

Make sure you check if the dimensions of this doubMatrix and the parameter's doubMatrix are the same (if not, return a new DoubleMatrix calling the first constructor passing 1, 1).

I think I wrote the part where it said calling first constructor passing 1,1 wrong.

package homework3;
public class DoubleMatrix
{
 private double[][] doubMatrix;
 public DoubleMatrix()
 {
 int row;
 int col;
 if(row > 0 && col > 0)
 {
 makeDoubMatrix(1,1);
 }
 else
 {
 row = 1;
 col = 1;
 }
 }
 
 public DoubleMatrix(double[][] tempArray) 
 {
 if(tempArray != null)
 {
 for(int i = 0; i < tempArray.length-1;i++)
 {
 if(tempArray[i].length == tempArray[i+1].length)
 {
 doubMatrix = tempArray;
 }
 }
 }
 else
 {
 makeDoubMatrix(1,1);
 }
 }
 
 public int getDim1()
 {
 return doubMatrix.length;
 }
 
 public int getDim2()
 {
 return doubMatrix[0].length;
 }
 
 private void makeDoubMatrix(int row, int col)
 {
 double[][] tempArray = new double[row][col];
 for(int i = 0;i < tempArray.length;i++)
 for(int j = 0;j < tempArray[i].length;j++)
 {
 tempArray[i][j] = Math.random() * (100); 
 } //end for 
 tempArray = doubMatrix;
 }
 
 public double[][] addMatrix(double[][] doubMatrix)
 { 
 this. doubMatrix = doubMatrix;
 double[][] tempArray = null;
 if(this.doubMatrix.length == doubMatrix.length)
 if(this.doubMatrix[0].length == doubMatrix[0].length)
 {
 for(int i = 0; i< this.doubMatrix.length;i++)
 for(int j = 0; j< this.doubMatrix[i].length;j++ )
 {
 tempArray[i][j] = this.doubMatrix[i][j] + doubMatrix[i][j];// add two matrices 
 }//end for 
 }
 else
 {
 return tempArray = new double[1][1];
 }
 
 return tempArray;
 }
}

Hi, can anyone review my addMatrix method to see if I am following the instruction under correctly? This is the instructions:

public method (I'm calling it addMatrix) that has ONLY ONE PARAMETER for a DoubleMatrix to add this doubMatrix (not changing this doubMatrix) and the parameter's doubMatrix and return a new DoubleMatrix (you'll need a local 2-dim. array to store the result of adding and pass to the constructor). Make sure you check if the dimensions of this doubMatrix and the parameter's doubMatrix are the same (if not, return a new DoubleMatrix calling the first constructor passing 1, 1).

I think I wrote the part where it said calling first constructor passing 1,1 wrong.

add Matrix method review

package homework3;
public class DoubleMatrix
{
 private double[][] doubMatrix;
 public DoubleMatrix()
 {
 int row;
 int col;
 if(row > 0 && col > 0)
 {
 makeDoubMatrix(1,1);
 }
 else
 {
 row = 1;
 col = 1;
 }
 }
 
 public DoubleMatrix(double[][] tempArray) 
 {
 if(tempArray != null)
 {
 for(int i = 0; i < tempArray.length-1;i++)
 {
 if(tempArray[i].length == tempArray[i+1].length)
 {
 doubMatrix = tempArray;
 }
 }
 }
 else
 {
 makeDoubMatrix(1,1);
 }
 }
 
 public int getDim1()
 {
 return doubMatrix.length;
 }
 
 public int getDim2()
 {
 return doubMatrix[0].length;
 }
 
 private void makeDoubMatrix(int row, int col)
 {
 double[][] tempArray = new double[row][col];
 for(int i = 0;i < tempArray.length;i++)
 for(int j = 0;j < tempArray[i].length;j++)
 {
 tempArray[i][j] = Math.random() * (100); 
 } //end for 
 tempArray = doubMatrix;
 }
 
 public double[][] addMatrix(double[][] doubMatrix)
 { 
 this. doubMatrix = doubMatrix;
 double[][] tempArray = null;
 if(this.doubMatrix.length == doubMatrix.length)
 if(this.doubMatrix[0].length == doubMatrix[0].length)
 {
 for(int i = 0; i< this.doubMatrix.length;i++)
 for(int j = 0; j< this.doubMatrix[i].length;j++ )
 {
 tempArray[i][j] = this.doubMatrix[i][j] + doubMatrix[i][j];// add two matrices 
 }//end for 
 }
 else
 {
 return tempArray = new double[1][1];
 }
 
 return tempArray;
 }
}

Hi, can anyone review my addMatrix method to see if I am following the instruction under correctly? This is the instructions:

public method (I'm calling it addMatrix) that has ONLY ONE PARAMETER for a DoubleMatrix to add this doubMatrix (not changing this doubMatrix) and the parameter's doubMatrix and return a new DoubleMatrix (you'll need a local 2-dim. array to store the result of adding and pass to the constructor). Make sure you check if the dimensions of this doubMatrix and the parameter's doubMatrix are the same (if not, return a new DoubleMatrix calling the first constructor passing 1, 1).

I think I wrote the part where it said calling first constructor passing 1,1 wrong.

addMatrix() method

Can anyone review my addMatrix() method to see if I am following the instructions correctly?

These are the instructions:

This is a public method (I'm calling it addMatrix()) that has only one parameter for a DoubleMatrix to add this doubMatrix (not changing this doubMatrix) and the parameter's doubMatrix and return a new DoubleMatrix (you'll need a local 2-dim. array to store the result of adding and pass to the constructor).

Make sure you check if the dimensions of this doubMatrix and the parameter's doubMatrix are the same (if not, return a new DoubleMatrix calling the first constructor passing 1, 1).

I think I wrote the part where it said calling first constructor passing 1,1 wrong.

package homework3;
public class DoubleMatrix
{
 private double[][] doubMatrix;
 public DoubleMatrix()
 {
 int row;
 int col;
 if(row > 0 && col > 0)
 {
 makeDoubMatrix(1,1);
 }
 else
 {
 row = 1;
 col = 1;
 }
 }
 
 public DoubleMatrix(double[][] tempArray) 
 {
 if(tempArray != null)
 {
 for(int i = 0; i < tempArray.length-1;i++)
 {
 if(tempArray[i].length == tempArray[i+1].length)
 {
 doubMatrix = tempArray;
 }
 }
 }
 else
 {
 makeDoubMatrix(1,1);
 }
 }
 
 public int getDim1()
 {
 return doubMatrix.length;
 }
 
 public int getDim2()
 {
 return doubMatrix[0].length;
 }
 
 private void makeDoubMatrix(int row, int col)
 {
 double[][] tempArray = new double[row][col];
 for(int i = 0;i < tempArray.length;i++)
 for(int j = 0;j < tempArray[i].length;j++)
 {
 tempArray[i][j] = Math.random() * (100); 
 } //end for 
 tempArray = doubMatrix;
 }
 
 public double[][] addMatrix(double[][] doubMatrix)
 { 
 this. doubMatrix = doubMatrix;
 double[][] tempArray = null;
 if(this.doubMatrix.length == doubMatrix.length)
 if(this.doubMatrix[0].length == doubMatrix[0].length)
 {
 for(int i = 0; i< this.doubMatrix.length;i++)
 for(int j = 0; j< this.doubMatrix[i].length;j++ )
 {
 tempArray[i][j] = this.doubMatrix[i][j] + doubMatrix[i][j];// add two matrices 
 }//end for 
 }
 else
 {
 return tempArray = new double[1][1];
 }
 
 return tempArray;
 }
}
edited tags
Link
200_success
  • 145.6k
  • 22
  • 190
  • 479
Loading
added 345 characters in body
Source Link
Corbin
  • 10.6k
  • 2
  • 31
  • 51
Loading
Source Link
Khoa Vo
  • 109
  • 5
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /