This is in DFM.java
This part is in the main class
Algebra.vect dx = new Algebra.vect(new double[] {2.0,3.0,4.0});
Algebra.matrix eij = new Algebra.matrix();
System.out.println(eij.get(1,1));
dx.set(1,4.0);
System.out.println(dx.get(1));
This is in Algebra.java
class Algebra {
public static class vect
{
double[] v = new double[3];
public vect()
{
v[0]=v[1]=v[2]=0;
}
public vect(double[] v)
{
this.v=v;
}
int tamanho()
{
return v.length;
}
double get(int i)
{
return v[i];
}
void set(double[] v)
{
this.v=v;
}
void set(int i, double n)
{
v[i]=n;
}
void print()
{
for(int i=0; i < v.length; i = i + 1)
System.out.print(v[i] + " ");
System.out.print("\n");
}
}
public static class operacoes
{
double prodInt(vect v1, vect v2)
{
return v1.get(0)*v2.get(0)+v1.get(1)*v2.get(1)+v1.get(2)*v2.get(2);
}
double[] somaVV(vect v1, vect v2)
{
return new double[] {v1.get(0)+v2.get(0), v1.get(1)+v2.get(1), v1.get(2)+v2.get(2) };
}
double[] prodMV(matrix m, vect v)
{
double[] Soma = new double[3];
Soma[0]=Soma[1]=Soma[2]=0;
for(int i=0;i< v.tamanho();i=i+1)
{
for(int j=0;i< v.tamanho();j=j+1)
{
Soma[i]=m[i][j]*v[j];
}
}
return Soma;
}
}
public static class matrix
{
double[][] m = new double[3][3];
public matrix()
{
for(int i=0;i< v.tamanho();i=i+1)
{
for(int j=0;i< v.tamanho();j=j+1)
{
m[i][j]=0;
}
}
}
public matrix(double[][] m )
{
this.m=m;
}
double get(int i,int j)
{
return m[i][j];
}
void set(double [][] m)
{
this.m=m;
}
void set(int i,int j, double n)
{
m[i][j]=n;
}
void print()
{
for(int i=0;i< v.tamanho();i=i+1)
{
for(int j=0;i< v.tamanho();j=j+1)
{
System.out.print(m[i][j] + " ");
}
System.out.print("\n");
}
System.out.print("\n");
}
}
Error
DFM.java:29: error: cannot find symbol
System.out.println(eij.get(1,1));
^
symbol: method get(int,int)
location: variable eij of type matrix
1 error
But when I ran with calls of eij method in commentary
dx.set(1,4.0);
System.out.println(dx.get(1));
This part where dx is of the vect class, worked well and is the code is similar to the matrix class
Can anyone help please?
Looks like the signature of your matrix
-class's get
-method is missing the modifier public
:
double get(int i,int j)
so it has "default" (package) visibility. Change it to
public double get(int i,int j)
and it should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.