Results 1 to 5 of 5
Thread: ComplexNumber.java I NEED HELPPP
- 04-14-2010, 04:17 AM #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.
void add (ComplexNumber c)
-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.
-
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.
- 04-14-2010, 07:16 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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!
- 04-14-2010, 07:43 AM #4
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 13
Start with this, in a file called 'ComplexNumber'
Java Code:public class ComplexNumber { final double r; final double i; public ComplexNumber(double r, double i) { this.r = r; this.i = i; } }
- 04-14-2010, 04:16 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
I think it's better for OPs workout first of all toadaly. :)
Similar Threads
-
helppp
By dadaman in forum New To JavaReplies: 2Last Post: 04-30-2008, 02:01 PM
Bookmarks