Results 1 to 5 of 5
  1. #1
    db7_turbo is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Unhappy 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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    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;
      }
    
    }

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. helppp
    By dadaman in forum New To Java
    Replies: 2
    Last Post: 04-30-2008, 02:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •