Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. Java and Math, yikes!

Create a class called Complex for performing arithmetic with complex numbers.
Complex numbers have the form
realPart + imaginaryPart * i (e.g., a + bi)
where i is : square root(1)

The class should contain:
• Two double data fields x and y that represent the real and imaginary part of a complex number.
• A no-arg constructor that creates a complex number (0 + 0i).
• A constructor that creates a Complex object with specified real and imaginary part of the complex number.
• Two get methods for data fields x and y, respectively.
• A method named add that returns the addition of this complex number with another. Complex numbers are added by adding the real and
imaginary parts of the summands. That is to say:
(a+bi) + (c+di) = (a+c) + (b+d)i
The method is: public Complex add(Complex c) {}
• A method named subtract that returns the subtraction of this complex
number with another. Subtraction is defined by:
(a+bi) + (c+di) = (a-c) + (b-d)i
The method is: public Complex subtract(Complex c) {}
• A method named multiply that returns the multiplication of this complex
with another. The multiplication of two complex numbers is defined by
the following formula:
( a+bi )( c+di ) = ( ac – bd ) + ( bc + ad )i
The method is: public Complex multiply(Complex c) {}
• AtoString() method that prints a Complex object in the form (a)+(b)i, where a is the real part and b is the imaginary part.

I don't even know how to do this is in math class, yet alone java, can someone point me in the right direction?

2. Re: Java and Math, yikes!

Hello and welcome to the forums.

The instructions are laid out infront of you..

You can at least start by creating a class called Complex and add the parts you understand.
Even beginners should know how to add two double variables and a method etc. This stuff is basics.

Please post your attempt at the code and we can take it from there.

3. Re: Java and Math, yikes!

Originally Posted by JavaPF
Hello and welcome to the forums.

The instructions are laid out infront of you..

You can at least start by creating a class called Complex and add the parts you understand.
Even beginners should know how to add two double variables and a method etc. This stuff is basics.

Please post your attempt at the code and we can take it from there.
I'm studying for a chem exam atm, but I shall try the methods later and get back to ya.

The second and third bullet points confuse me though. We really never talked about "constructors"

Also, for the get methods, do I just do something like this:
Program program = new Program();
Class progClass = program.getClass();
Method Getx = progClass.getX (or Method GetY = progClass.getY

4. Re: Java and Math, yikes!

Originally Posted by Tfence
We really never talked about "constructors"
That shouldn't preclude you from trying to learn about them yourself...google the term and you will find ample descriptions

5. Re: Java and Math, yikes!

Originally Posted by copeg
That shouldn't preclude you from trying to learn about them yourself...google the term and you will find ample descriptions

Thank you.