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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Java and Math, yikes!

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default 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.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java and Math, yikes!

    Quote Originally Posted by JavaPF View Post
    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. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java and Math, yikes!

    Quote Originally Posted by Tfence View Post
    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. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java and Math, yikes!

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

    Thank you.

Similar Threads

  1. Vector Math in Java
    By Spidey1980 in forum Java Theory & Questions
    Replies: 7
    Last Post: August 18th, 2011, 12:05 PM
  2. Confusion with Math.toDegrees() and Math.toRadians(). Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 3
    Last Post: June 23rd, 2011, 01:28 AM
  3. help w/ PI Math java program
    By robertsbd in forum What's Wrong With My Code?
    Replies: 8
    Last Post: February 16th, 2011, 09:43 PM
  4. Help need on math java program
    By zidangus in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 6th, 2010, 07:41 PM
  5. Math in Java?
    By [Kyle] in forum Java Theory & Questions
    Replies: 3
    Last Post: September 23rd, 2009, 12:21 PM