Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me debug my Java code! These are the errors I got: HW 2 _ Tester.java: 2 0 6 : error: cannot find symbol

Please help me debug my Java code!
These are the errors I got:
HW2_Tester.java:206: error: cannot find symbol
MathVector sum = new MathVector(vectors[0].getDimension());
^
symbol: variable vectors
location: class MathVector
HW2_Tester.java:207: error: cannot find symbol
for(Mathvector vectors : vectors){
^
symbol: variable vectors
location: class MathVector
HW2_Tester.java:207: error: cannot find symbol
for(Mathvector vectors : vectors){
^
symbol: class Mathvector
location: class MathVector
3 errors
error: compilation failed
This is my code:
class MathVector {
private final int dim;
private final double[] values;
public MathVector(int N){
this.dim = N;
this.values = new double[dim];
}
public MathVector(double... arr){
dim = arr.length;
values = new double[dim];
for (int i =0; i < dim; i++){
values[i]= arr[i];
}
}
public MathVector(MathVector v){
//this(v.values)
dim = v.dim;
values = new double[dim];
for (int i =0; i < dim; i++){
values[i]= v.values[i];
}
}
public static MathVector vec2DfromPolar(double r, double theta){
double x = r * Math.cos(theta);
double y = r * Math.sin(theta);
return new MathVector(x,y);
}
public static MathVector vec3DfromPolar(double r, double theta, double phi){
double x = r * Math.sin(theta)* Math.cos(phi);
double y = r * Math.sin(theta)* Math.sin(phi);
double z = r * Math.cos(theta);
return new MathVector(x, y, z);
}
public int getDimension(){
return dim;
}
public double getValue(int idx){
return values[idx-1];
}
public void setValue(int idx, double val){
values[idx-1]= val;
}
public double dotWith(MathVector other){
double dotProd =0;
for(int i =0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions