HW HELP! Input not being read?

The program asks for the user to enter a real number and an imaginary number followed by another set of a real number and an imaginary number. It then takes those and adds them, subtracts them, and multiplies them then displays it to the screen. However, after the user inputs the numbers, it does the operations, but it doesn't do the math right. For addition, only the second real number and second imaginary number inputted are scanned, so it adds the second real number to itself and the second imaginary number to itself instead of adding the first with the second like it's supposed to. The subtraction and multiplication operations don't scan any of the input at all though. I have one of the input used and output it produced at the very bottom commented out. If someone could tell me what I did wrong, I would greatly appreciate it, and thanks in advance!

import java.util.Scanner;

publicclass Complex

{

/** declare variables */

publicstaticdouble real;

publicstaticdouble imaginary;

/** default constructor */

public Complex()

{

real = 0.0;

imaginary = 0.0;

}

/** assigns r to real and i to imaginary */

public Complex(double r,double i)

{

real = r;

imaginary = i;

}

/** assigns r to real */

publicvoid setReal(double r)

{

real = r;

}

/** assigns i to imaginary */

publicvoid setImaginary(double i)

{

imaginary = i;

}

/** assigns real to r and returns it */

publicdouble getReal()

{

double r = real;

return real;

}

/** assigns imaginary to i and returns it */

publicdouble getImaginary()

{

double i = imaginary;

return imaginary;

}

/** declares and initializes realPart */

//public void setRealPart(double realPart)

//{

//double alpha;

//double realPart = realPart + alpha * i;

//}

/** initializes object to alpha */

//public void setAlpha()

//{

//double alpha;

//Complex = alpha + alpha * i;

//}

/** check for equality */

public Boolean equals(Complex C)

{

return((real == C.real) && (imaginary == C.imaginary));

}

/** add */

publicstatic Complex add(Complex C)

{

/*Complex add;

double r = real + C.real;

double i = imaginary + C.imaginary;

add = new Complex(r, i);

return add; */

returnnew Complex(real + C.real, imaginary + C.imaginary);

}

/** subtract */

publicstatic Complex subtract(Complex C)

{

/*Complex subtract;

double r = real - C.real;

double i = imaginary - C.imaginary;

subtract = new Complex(r, i);

return subtract; */

returnnew Complex(real - C.real, imaginary - C.imaginary);

}

/** multiply */

publicstatic Complex multiply(Complex C)

{

/*Complex multiply;

double r = real * C.real - imaginary * C.imaginary;

double i = real * C.imaginary + imaginary * C.real;

multiply = new Complex(r, i);

return multiply; */

returnnew Complex(real * C.real - imaginary * C.imaginary, real * C.imaginary + imaginary * C.real);

}

/** displays to screen */

public String toString()

{

String imaginarySymbol = (imaginary < 0) ?" - " :" + ";

return (real + imaginarySymbol + imaginary +"i");

}

/** driver */

publicstaticvoid main(String[] args)

{

Complex A =new Complex();

Complex B =new Complex();

Complex C =new Complex();

Scanner input =new Scanner(System.in);

/** input and scan first real number */

System.out.println("Enter a double for the first real number: ");

A.setReal(input.nextDouble());

/** input and scan first imaginary number */

System.out.println("\nEnter a double for the first imaginary number: ");

A.setImaginary(input.nextDouble());

/** input and scan second real number */

System.out.println("\nEnter a double for the second real number: ");

B.setReal(input.nextDouble());

/** input and scan second imaginary number */

System.out.println("\nEnter a double for the second imaginary number: ");

B.setImaginary(input.nextDouble());

/** add complex numbers and display to screen*/

A.add(B);

System.out.println(A.toString() +" + " + B.toString() +" = " + A.add(B));

/** subtract complex numbers and display to screen*/

A.subtract(B);

System.out.println(A.toString() +" - " + B.toString() +" = " + A.subtract(B));

/** multiply complex numbers and display to screen*/

A.multiply(B);

System.out.println(A.toString() +" * " + B.toString() +" = " + A.multiply(B));

}

}

/**

Enter a double for the first real number:

1.0

Enter a double for the first imaginary number:

1.5

Enter a double for the second real number:

2.0

Enter a double for the second imaginary number:

2.5

4.0 + 5.0i + 4.0 + 5.0i = 8.0 + 10.0i

0.0 + 0.0i - 0.0 + 0.0i = 0.0 + 0.0i

0.0 + 0.0i * 0.0 + 0.0i = 0.0 + 0.0i

Press any key to continue . . .

*/

[9085 byte] By [JWest46088a] at [2007-10-3 6:41:56]
# 1
> public static double real;> public static double imaginary;The attributes should not be static.Kaj
kajbja at 2007-7-15 1:31:06 > top of Java-index,Java Essentials,New To Java...