Using Eclipse Edit Student Part Nothing Else Modified Public Class Mathvector 2d Array Hol Q43888021
using eclipse
only edit the // student part
nothing else should be modified
public class MathVector {
// 2D array to hold the numbers of the vector, either along thecolumns or
rows
private double[][] data;
// set to true for a row vector and false for a columnvector
private boolean isRowVector;
// count of elements in the vector
private int vectorSize;
/**
* Creates a new row or column vector.
* For a row vector, the input array is expected to have 1 rowand a positive
number of columns,
* and this number of columns represents the vector’s length.
* For a column vector, the input array is expected to have 1column and a
positive number of rows,
* and this number of rows represents the vector’s length.
*
* @param data – a 2D array to hold the numbers of the vector
* @throws IllegalArgumentException if the numbers of rows andcolumns in the
input 2D array is not
* compatible with a row or column vector
*/
public MathVector(double[][] data) {
if(data.length == 0)
throw new IllegalArgumentException(“Number of rows must be
positive.”);
if(data[0].length == 0)
throw new IllegalArgumentException(“Number of columns mustbe
positive.”);
if(data.length == 1) {
// This is a row vector with length = number of columns.
this.isRowVector = true;
this.vectorSize = data[0].length;
}
else if(data[0].length == 1) {
// This is a column vector with length = number of rows.
this.isRowVector = false;
this.vectorSize = data.length;
}
else
throw new IllegalArgumentException(“Either the number of rowsor
the number of columns must be 1.”);
// Create the array and copy data over.
if(this.isRowVector)
this.data = new double[1][vectorSize];
else
this.data = new double[vectorSize][1];
for(int i=0; i < this.data.length; i++) {
for(int j=0; j < this.data[0].length; j++) {
this.data[i][j] = data[i][j];
}
}
}
/**
* Determines whether this vector is “equal to” another vector,where
equality is
* defined as both vectors being row (or both being column),having the same
* vector length, and containing the same numbers in the samepositions.
*
* @param other – another vector to compare
*/
public boolean equals(Object other) {
if(!(other instanceof MathVector))
return false;
MathVector otherVec = (MathVector)other;
// STUDENT: Fill in remaining code to determine equality of twovector
objects, do not return false.
return false;
}
/**
* Generates a returns a new vector that is the transposedversion of this
vector.
*/
public MathVector transpose() {
// STUDENT: Fill in with code to accomplish the method contractabove,
do not return null.
return null;
}
/**
* Generates and returns a new vector representing the sum ofthis vector and
another vector.
*
* @param other – another vector to be added to this vector
* @throws IllegalArgumentException if the other vector and thisvector are
not both row vectors of
* the same length or column vectors of the same length
*/
public MathVector add(MathVector other) {
// STUDENT: Fill in with code to accomplish the method contractabove,
do not return null.
return null;
}
/**
* Computes and returns the dot product of this vector andanother vector.
*
* @param other – another vector to be combined with this vectorto produce
the dot product
* @throws IllegalArgumentException if the other vector and thisvector are
not both row vectors of
* the same length or column vectors of the same length
*/
public double dotProduct(MathVector other) {
// STUDENT: Fill in with code to accomplish the method contractabove,
do not return 0.
return 0;
}
/**
* Computes and returns this vector’s magnitude (also known as avector’s
length) .
*/
public double magnitude() {
// STUDENT: Fill in with code to accomplish the method contractabove,
do not return 0.
return 0;
}
/**
* Generates and returns a normalized version of this vector.
*/
public MathVector normalize() {
// STUDENT: Fill in with code to accomplish the method contractabove,
do not return null.
return null;
}
/**
* Generates and returns a textual representation of thisvector.
* For example, “1.0 2.0 3.0 4.0 5.0” for a sample row vector oflength 5 and
* “1.0
* 2.0
* 3.0
* 4.0
* 5.0″ for a sample column vector of length 5.
* In both cases, notice the lack of a newline or space after thelast
number.
*/
public String toString() {
// STUDENT: Fill in with code to accomplish the method contractabove,
do not return null.
return null;
}
}
Expert Answer
Answer to using eclipse only edit the // student part nothing else should be modified public class MathVector { // 2D array to hol…
OR