Question: JAVA Create a ComplexNumber class with variables real and imaginary . The values can be positive or negative. Create a Constructor method for this class.

JAVA

Create a ComplexNumber class with variables real and imaginary. The values can be positive or negative.

Create a Constructor method for this class.

Create a toString() method which shows the ComplexNumber in this format, a + bi, or a - bi or -a + bi or -a - bi, depending on the values of real and imaginary. For fractions show 2 digits after the decimal point.

Create add, sub and multiply methods which adds, subtracts and multiply two ComplexNumber. These functions should take a single ComplexNumber parameter and update the current ComplexNumber with the new value. Following are the rules for add, sub and multiply: (a+bi) + (c+di) = (a+c) + (b+d)i (a+bi)(c+di) = ac + adi + bci - bd

Create a driver class which generates several Complex numbers and test the created methods.

What you need:

ComplexNumber java class

ComplexNumberTest java class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!