Question: Write a program for complex Numbers in java using Objects. There should be 2 different programs One will that defines the object - Complex And
Write a program for complex Numbers in java using Objects. There should be 2 different programs
One will that defines the object - Complex
And a usage file - ComplexUse
A complex number has 2 parts a real number and an imaginary number
Your program should do the following;
addition of 2 complex numbers cn1, cn2
cn1's real part + cn2's real part
cn1's imaginary part + cn2's imaginary part
subtraction of 2 complex numbers cn1, cn2
cn1's real part - cn2's real part
cn1's imaginary part - cn2's imaginary part
multiplication of 2 complex numbers
( (cn1's real part cn2's real part) - (cn1's imaginary part cn2's imaginary part) ) +
( (cn1's real part cn2's imaginary part) + (cn1's imaginary part cn2's real part) )
For 2 complex numbers : (a+ib) & (c+id)
addition : ( (a+c) + i(b+d) )
subtraction : ( (a-c) + i(b-d) )
multiplication : ( (ac-bd) + i(ad+bc) )
Also Complex program shall have fields/properties for a complex number(i.e. 2 double numbers)
constructor which takes in 2 double values as parameters & assigns them to the fields.
add method
subtract method
multiply method
While the complexuse program shall have Inside the main, the following will be needed to accomplish our goal : declare 2 ComplexNumber objects
get 4 double values from user (because we need 2 values to create a complex number - first 2 double numbers form the first complex number & the second 2 double numbers form the second complex number)
create the 2 complex numbers by using the values gotten from user.
Use the methods (add, subtract, multiply) & display the result
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
