I'm trying to make a method which adds two vectors, but am running into trouble.
The specific problem I am getting is an error stating that the constructor NumVector(double[]) is undefined when I try to make a new numVector "sumVector."
I included my whole code, but the specific problem lies within the sum method.
public class NumVector {
//array of vectors:
private double vector[];
private static final int DEFAULT_SIZE = 3; //default size set to 3.
public NumVector(int size){
vector = new double[size];
}
public NumVector (NumVector v){
vector = new double[v.vector.length];
for(int i = 0; i < vector.length; i++)
vector[i] = v.vector;
}
public NumVector(){
vector = new double [DEFAULT_SIZE];
}
public void setValue(int i, double value){
//Sets value of "i"th spot to value inputted.
vector[i] = value;
}
public double getValue (int i){
if (i >= 0 && i < vector.length)
return vector[i];
else
return 0;
}
public NumVector sum(NumVector other){
double sumArray[] = vector;
for (int i = 0; i < sumArray.length; i++){
sumArray[i] = vector[i] + other.getValue(i);
}
NumVector sumVector = new NumVector(sumArray);
return sumVector;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
is there a better way to approach adding two vectors?