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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started