I am creating a Vector
class for educational purposes. This class has standard getters & setters, and now I want to add support for adding two vectors.
When I try to call result.setVectorValue
, I get the error cannot resolve method setVectorValue. How can I overcome my trouble?
Here is the full code of my class:
public class Vector <T1> {
private T1[] vectorArray;
public Vector(){
}
public Vector(T1[] a){
this.vectorArray = a;
}
public void setVector(T1[] a){
this.vectorArray = a;
}
public void setVectorValue(T1 value, int index){
this.vectorArray[index] = value;
}
public T1[] getVector(){
return this.vectorArray;
}
public T1 getVectorValue(int index){
return this.vectorArray[index];
}
public int getVectorLength(){
return this.vectorArray.length;
}
public String toString() {
if (vectorArray == null)
return null;
return vectorArray.getClass().getName() + " " + vectorArray;
}
public T1[] plus(T1[] inputVector, T1[] whatToPlusVector){
Vector <T1> result = new Vector<T1>();
int index=0;
for(T1 element : inputVector){
result.setVectorValue(element, index);
index++;
}
for(T1 element : whatToPlusVector){
result.setVectorValue(element, index);
index++;
}
return result;
}
}