Question: Please make changes to the following java code following the instruciton of tasks posted with this question. Please make use of the resources, the code

Please make changes to the following java code following the instruciton of tasks posted with this question. Please make use of the resources, the code should not be too complicated. The code is correct if it runs with the test code below correctly. Thank you
The code to be edited:
class MathVector {
final int dim;
final double[] values;
public MathVector(int N){
dim = N;
values = new double[N];
}
public MathVector(double[] arr){
dim = arr.length;
values = new double[arr.length];
}
public MathVector(MathVector v){
dim =0;
values = null;
}
public static MathVector vec2DfromPolar(double r, double theta){
return new MathVector(0);
}
public static MathVector vec3DfromPolar(double r, double theta, double phi){
return new MathVector(0);
}
public int getDimension(){ return 0; }
public double getValue(int idx){ return 0; }
public void setValue(int idx, double val){}
public double dotWith(MathVector other){ return 0; }
public double getMagnitude(){ return 0; }
public void scaleBy(double scalar){}
public static MathVector multiply(double scalar, MathVector v){
return new MathVector(0);
}
public void shiftBy(MathVector other){}
public static MathVector add(MathVector v1, MathVector v2){
return new MathVector(0);
}
public static MathVector add(MathVector... vs){
return new MathVector(0);
}
public boolean equals(MathVector other){ return false; }
public String toString(){ return ""; }
public void print(){}
}
The code to be tested:
class HW2_Tester {
public static void main(String[] args){
MathVector v1= new MathVector(1);
MathVector v2= new MathVector(1.0,2.0);
MathVector v3= new MathVector(v2);
System.out.println(v1.getDimension()+""+ v2.getDimension()); //12
System.out.println(v1.getValue(1)); //0.0
System.out.print('
');
v3.setValue(2,3.0);
System.out.println(v1.toString()); //[0.0]
System.out.println(v2); //[1.0,2.0]
v3.print(); //[1.0,3.0]
System.out.print('
');
MathVector.vec2DfromPolar(2, Math.PI /3).print();
// close to [1.0, Math.sqrt(3.0)]
MathVector.vec3DfromPolar(4, Math.PI /6, Math.PI /3).print();
// close to [1.0, Math.sqrt(3.0),2* Math.sqrt(3)]
System.out.print('
');
MathVector v = new MathVector(1,2,0,0);
MathVector w = new MathVector(0,0,3,4);
final MathVector e1= new MathVector(1,0,0,0);
final MathVector e2= new MathVector(0,1,0,0);
final MathVector e3= new MathVector(0,0,1,0);
final MathVector e4= new MathVector(0,0,0,1);
System.out.println(v.dotWith(e1)); //1.0
System.out.println(v.dotWith(e2)); //2.0
System.out.println(w.dotWith(w)); //25.0
System.out.println(w.getMagnitude()); //5.0
System.out.print('
');
System.out.println(MathVector.multiply(2, w)); //[0.0,0.0,6.0,8.0]
w.print(); // w unchanged by line before //[0.0,0.0,3.0,4.0]
w.scaleBy(2);
w.print(); // w changed by line before //[0.0,0.0,6.0,8.0]
System.out.print('
');
System.out.println(MathVector.add(v, w)); //[1.0,2.0,6.0,8.0]
v.print(); // v unchanged by line before //[1.0,2.0,0.0,0.0]
w.print(); // w unchanged by line before //[0.0,0.0,6.0,8.0]
System.out.print('
');
v.shiftBy(w);
v.print(); // v changed by line before //[1.0,2.0,6.0,8.0]
w.print(); // w unchanged by line before //[0.0,0.0,6.0,8.0]
System.out.print('
');
MathVector linearCombination = MathVector.add(
MathVector.multiply(8, e1), MathVector.multiply(7, e2),
MathVector.multiply(6, e3), MathVector.multiply(5, e4)
);
linearCombination.print(); //[8.0,7.0,6.0,5.0]
System.out.print('
');
System.out.println(!e1.equals(e2)); // true
System.out.println(!e2.equals(e3)); // true
System.out.println(!e3.equals(e4)); // true
System.out.println(!(new MathVector(4)).equals(new MathVector(5))); // true
System.out.println(v.equals(v)); // true
System.out.println(w.equals(w)); // true
System.out.println(w.equals(new MathVectWe have
 Please make changes to the following java code following the instruciton

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!