I made a class called Complex which holds 3 methods. Then i created another file called complextest

I'm trying to invoke the methods in complex through complextest but getting errors in the complextest

I'm not sure what I'm doing wrong or what I need to do to resolve this problem.

here is the code for complex

public class Complex

{

public Complex()

{

}

public void add(float w, float x, float y, float z)

{

float a = w + y;

float b = x + z;

System.out.println(a + " + " + b + "i");

}

public void subtract(float w, float x, float y, float z)

{

float a = w - y;

float b = x - z;

System.out.println(a + " + " + b + "i");

}

public void printComplex(float w, float x, float y, float z)

{

System.out.print( "(" + w + "," + x + ")");

System.out.println(" (" + y + "," + z + ")");

}

}

here is the code for complextest

import javax.swing.JOptionPane;

import java.lang.String;

public class Complextest {

public static void main(String args[])

{

String I, I2; //user input for the imagionary parts

String R, R2; //user input for the real parts

float real, real2; //to be used for calculations

float imag, imag2; //to be used for calculations

//recieve input from user

R = JOptionPane.showInputDialog("Enter the real part of the first complex num.");

I = JOptionPane.showInputDialog("Enter the imagionary part of the first complex num.");

R2 = JOptionPane.showInputDialog("Enter the real part of the second complex num.");

I2 = JOptionPane.showInputDialog("Enter the imagionary part of the second complex num.");

//convert string input into float to be used for calculations

real = Float.parseFloat(R);

real2 = Float.parseFloat(R2);

imag = Float.parseFloat(I);

imag2 = Float.parseFloat(I2);

Complex complex = new Complex(R, I, R2, I2);

Complex.add(real, imag, real2, imag2);

Complex.subtract(real, imag, real2, imag2);

Complex.printComplex(real, imag, real2, imag2);

/*method calls

add(real, imag, real2, imag2);

subtract(real, imag, real2, imag2);

printComplex(real, imag, real2, imag2);*/

}

}

and here is the errors that I'm receiving:

Complextest.java [33:1] cannot resolve symbol

symbol : class Complex

location: class Complextest

Complex complex = new Complex(R, I, R2, I2);

^

Complextest.java [33:1] cannot resolve symbol

symbol : class Complex

location: class Complextest

Complex complex = new Complex(R, I, R2, I2);

^

Complextest.java [34:1] cannot resolve symbol

symbol : variable Complex

location: class Complextest

Complex.add(real, imag, real2, imag2);

^

Complextest.java [35:1] cannot resolve symbol

symbol : variable Complex

location: class Complextest

Complex.subtract(real, imag, real2, imag2);

^

Complextest.java [36:1] cannot resolve symbol

symbol : variable Complex

location: class Complextest

Complex.printComplex(real, imag, real2, imag2);

^

5 errors

Errors compiling Complextest.

Thanks for the help.

I'm trying to invoke the methods in complex through complextest but getting errors in the complextest

I'm not sure what I'm doing wrong or what I need to do to resolve this problem.

here is the code for complex

public class Complex

{

public Complex()

{

}

public void add(float w, float x, float y, float z)

{

float a = w + y;

float b = x + z;

System.out.println(a + " + " + b + "i");

}

public void subtract(float w, float x, float y, float z)

{

float a = w - y;

float b = x - z;

System.out.println(a + " + " + b + "i");

}

public void printComplex(float w, float x, float y, float z)

{

System.out.print( "(" + w + "," + x + ")");

System.out.println(" (" + y + "," + z + ")");

}

}

here is the code for complextest

import javax.swing.JOptionPane;

import java.lang.String;

public class Complextest {

public static void main(String args[])

{

String I, I2; //user input for the imagionary parts

String R, R2; //user input for the real parts

float real, real2; //to be used for calculations

float imag, imag2; //to be used for calculations

//recieve input from user

R = JOptionPane.showInputDialo

I = JOptionPane.showInputDialo

R2 = JOptionPane.showInputDialo

I2 = JOptionPane.showInputDialo

//convert string input into float to be used for calculations

real = Float.parseFloat(R);

real2 = Float.parseFloat(R2);

imag = Float.parseFloat(I);

imag2 = Float.parseFloat(I2);

Complex complex = new Complex(R, I, R2, I2);

Complex.add(real, imag, real2, imag2);

Complex.subtract(real, imag, real2, imag2);

Complex.printComplex(real,

/*method calls

add(real, imag, real2, imag2);

subtract(real, imag, real2, imag2);

printComplex(real, imag, real2, imag2);*/

}

}

and here is the errors that I'm receiving:

Complextest.java [33:1] cannot resolve symbol

symbol : class Complex

location: class Complextest

Complex complex = new Complex(R, I, R2, I2);

^

Complextest.java [33:1] cannot resolve symbol

symbol : class Complex

location: class Complextest

Complex complex = new Complex(R, I, R2, I2);

^

Complextest.java [34:1] cannot resolve symbol

symbol : variable Complex

location: class Complextest

Complex.add(real, imag, real2, imag2);

^

Complextest.java [35:1] cannot resolve symbol

symbol : variable Complex

location: class Complextest

Complex.subtract(real, imag, real2, imag2);

^

Complextest.java [36:1] cannot resolve symbol

symbol : variable Complex

location: class Complextest

Complex.printComplex(real,

^

5 errors

Errors compiling Complextest.

Thanks for the help.

Join the community to see this answer!

Join our exclusive community to see this answer & millions of others.

Unlock 1 Answer and 6 Comments.

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert

See if this solution works for you by signing up for a 7 day free trial.

Unlock 1 Answer and 6 Comments.

Try for 7 days”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.