Hi everyone,
I am a beginner in java. I am still trying to learn the structure and other basic stuff.
I am trying to add some code so that the methods in main() work correctly.
class Complex {
double real, img;
void setValues(double i, double x){
real=i;
img=x;
}
public double getRealPart(){
double a=real;
}
public double getImagPart(){
double b=img;
}
public double getMagnitude(){
double magn=sqrt(real*real+img*img);
}
public class TestComplex {
public static void main (String[] argv)
{
Complex c1 = new Complex();
c1.setValue (1.0, 1.0);
System.out.println ("c1's real part = " + c1.getRealPart()
+ "\n" +
"c1's imag part = " + c1.getImagPart());
System.out.println ("|c1| = " + c1.getMagnitude());
Complex c2 = new Complex();
c2.setValue (6.0, 8.0);
System.out.println ("c2's real part = " + c2.getRealPart()
+ "\n" +
"c2's imag part = " + c2.getImagPart());
System.out.println ("|c2| = " + c2.getMagnitude());
}
}
what is wrong with my code?