- Jul 29, 2001
- 27,703
- 12
- 81
Okay, I've got an object called ComplexNumber with 2 attributes, realpt and imagpt.
I've made a few of these objects via
ComplexNumber A = new ComplexNumber(realpt, imagpt);
Same for B.
I now want to add the two numbers. How do I define my add function so that the call:
A.add(B);
Adds the real part of A to the real part of B and the imaginary part of A to the imaginary part of B?
I know how to do the math behind it, I just don't know what my add function should look like. I've got:
public void add(what goes here??? ComplexNumber?)
{
real = real + realpt???
imaginary = imaginary + imagpt???
}
I've got two .java files. One is ComplexNumber, and it has my constructors, and my add/set/write/divide functions, and a ComplexNumberUser which asks the user for realpt and imagpt, creates the instances of ComplexNumber, and does the function calls...
I've made a few of these objects via
ComplexNumber A = new ComplexNumber(realpt, imagpt);
Same for B.
I now want to add the two numbers. How do I define my add function so that the call:
A.add(B);
Adds the real part of A to the real part of B and the imaginary part of A to the imaginary part of B?
I know how to do the math behind it, I just don't know what my add function should look like. I've got:
public void add(what goes here??? ComplexNumber?)
{
real = real + realpt???
imaginary = imaginary + imagpt???
}
I've got two .java files. One is ComplexNumber, and it has my constructors, and my add/set/write/divide functions, and a ComplexNumberUser which asks the user for realpt and imagpt, creates the instances of ComplexNumber, and does the function calls...