class Complex {
  double real, img;
 
        void setValue(double i, double x){
                real=i;
                img=x;
        }
        public double getRealPart(){
                double a=real;
                return a;
        }
        public double getImagPart(){
                double b=img;
                return b;
        }
        public double getMagnitude(){
                double magn=Math.sqrt(real*real+img*img);
                return magn;
        }
        public Complex add(Complex c){
                return new Complex(real+c.real, img+c.img);
        }
        public Complex multiply(Complex c){
                return new Complex(real*c.real-img*c.img,real*c.img+img*c.real);
        }
        public String toString(){
                return "real part is" + real + "Imaginary part is" + img;
        }
}
public class TestComplex {

  public static void main (String[] argv)
  {
    Complex c1 = new Complex();
    Complex c2 = new Complex (4.35, 9.002); // (4.35, 9.002)
    Complex c3 = new Complex (8.93);        // (8.93, 0)
    Complex c4 = c1.add (c2);
    Complex c5 = c2.multiply (c3);
    Complex c6 = new Complex (4.35, 9.002);

    System.out.println ("c6 = " + c6);

    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());

    double magSum = c1.getMagnitude() + c2.getMagnitude();
    System.out.println ("|c1| + |c2| = " + magSum);
    
  }
}

I am getting the errors:

[32] $ javac TestComplex.java
TestComplex.java:21: cannot find symbol
symbol : constructor Complex(double,double)
location: class Complex
return new Complex(real+c.real, img+c.img);
^
TestComplex.java:24: cannot find symbol
symbol : constructor Complex(double,double)
location: class Complex
return new Complex(real*c.real-img*c.img,real*c.img+img*c.real);
...

You have not specified a constructor for class Complex that accepts two doubles as parameters. There are two things you could do:

1- Rename void "setValue" to "public Complex" and give the Complex constructor two doubles as arguments.

Or,

2- Declare a two argument constructor that sends the two doubles to the method setValue.

I hope this helps.

Edited 7 Years Ago by majestic0110: tidy up

sorry for the late reply, i was kind busy with school and work.

Thank you for ur help, I followed your instructions and got the problem fixed.

This question has already been answered. Start a new discussion instead.