1. Member
Join Date
Apr 2010
Posts
1
Rep Power
0

ComplexNumber.java I NEED HELPPP

I'm doing programs out of this old java book, I took Computer programming last year at school and used the book but I haven't did the stuff in a while and I'm stuck on a proplem. It says:

Create a class called ComplexNumber that implements complex numbers. The class should have two fields, real and imaginary which hold the real and imaginary parts of the number.

- Create a ComplexNumber object with real and imaginary parts specified by r and i
ComplexNumber (double r, double i)
-Add the complex number represented by c to the ComplexNumber.
-Multiply the ComplexNumber by the complex number represented by c.
void multiply (ComplexNumber c)
-Return the real portion of the ComplexNumber.
double getReal ()
-Return the imaginary portion of the ComplexNumber.
double getImaginary ()
-Return a String that contains a formatted version of the ComplexNumber.
String formatAsString ()

Create a program called TestComplex that creates two pairs of ComplexNumber objects and outputs them, their sum, and their product.

Any help will be most appreciated.

2. The key is to break the big problem into multiple little problems and then solve each one in isolation. For a decent essay on doing just this, please see the last link in my signature. The next key is to just dive in and try to solve it. If you fail, then you can come back with your code which will allow us to be able to give you much more specific help rather than general help (such as this post). Simply put, the more you push your brain, the quicker you'll learn.

Much luck!
Last edited by Fubarable; 04-14-2010 at 05:18 AM.

3. As Fubarable says, start from the creating class you want. Can you create it and show it here? We'll help you to do that. Good luck!

4. Senior Member
Join Date
Jan 2009
Posts
671
Rep Power
6

Java Code:
```public class ComplexNumber {

final double r;
final double i;

public ComplexNumber(double r, double i) {
this.r = r;
this.i = i;
}

}```