I am making a class that mimics a Gaussian integer. I use the constructor in my add method to add two two parts of gInt, and then return a new gInt, which is the sum. But for some reason, when I try to implement this method, Java says gInt is required when I initialize a new gInt and find a void. Why should it be? I included the class below and indicated which line is causing this error.
public class gInt {
private int real;
private int imag;
public void gInt(int r)
{
imag=0;
real=r;
}
public void gInt(int r, int i)
{
real=r;
imag=i;
}
gInt add(gInt rhs)
{
gInt added;
int nReal=this.real+rhs.real;
int nImag=this.imag+rhs.real;
added= gInt(nReal,nImag);
return added;
}
}
source
share