Hi I am struggling with a java problem.
I am trying to understand how to assign value x to new elements added to a vector where the existing elements would remain unchanged, e.g. if it was resized from 3 to 5 then the 4th and 5th would have value x.
Additionally, in the next class I want to add another vector _v to the current vector. If this is bigger than the length of the current vector that reSize(int _size) is called. How do I write this?
public class Vector {
private double[] doubElements;
public Vector(double[] _elements) {
this.doubElements = _elements;
}
public int getVectorSize() {
return doubElements.length;
}
public Vector reSize(int _size) {
if (_size == (doubElements.length - 1) || _size <= 0){
return null;
} else if (_size < (doubElements.length - 1)) {
return new Vector(new double[]{doubElements[_size]});
} else {
return new Vector(new double[]{doubElements.add(-1.0)});
}
}
public Vector add(Vector _v) {
Vector.this.add(_v);
if (getVectorSize(doubElements.length)) {
reSize()...
return null;
}
}