Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The UML class shown below is for the complex number representation. 3.1 Ex: The My Complex class '(real+imagi), e.g., (3+4i) In radians My Complex -real:
The UML class shown below is for the complex number representation. 3.1 Ex: The My Complex class '(real+imagi)", e.g., "(3+4i)" In radians My Complex -real: double = 0.0 -imag:double = 0.0 +MyComplex() +MyComplex(real: double, imag:double) +getReal():double +setReal(real:double):void +getImag(): double +set Imag(imag: double):void +setValue(real: double, imag: double):void +toString(): String +isReal(): boolean +isImaginary(): boolean +equals(real: double, imag: double): boolean +equals(another:MyComplex): boolean +magnitude(): double +argument(): double +add(right: MyComplex):MyComplex +addNew(right: MyComplex): My Complex +subtract(right:MyComplex):My Complex +subtractNew(right: MyComplex):MyComplex +multiply(right: MyComplex): My Complex +divide (right: MyComplex): MyComplex +conjugate():My Complex add(), subtract(),multiply(),divide(): add/subtract/multiply/divide the given instance right into this instance, and return this instance. addNew(), subtractNew(): add/subtract this and right, and return a new instance, this instance shall not be changed. conjugate(): on this instance Question (1) A class called MyComplex, which models complex numbers x + yi, is designed as shown in the class diagram given above. It contains: Two instance variables named real (double) and imag (double) which stores the real and imaginary parts of the complex number, respectively. 1. A constructor that creates a MyComplex instance with the given real and imaginary values. 2. A default constructor that creates a My Complex at 0.0 + 0.0 i. 3. Getters and setters for instance variables real and imag. 4. A method setValue() to set the value of the complex number (both real and imaginary parts) 5. Methods is Real() and isImaginary() that returns true if this complex number is real or imaginary, respectively. 6. A method equals(double real, double imag) that returns true if this complex number is equal to the given complex number (real, imag). a. Hints: b. return (this.real == real && this.imag == imag); 7. Methods add(MyComplex right) and subtract(MyComplex right) that adds and subtract the given MyComplex instance (called right), into/from this instance and returns this instance. (a + bi) + (c + di) = (a+c) + (b+d)i (a + bi) - (c + di) = (a-c) + (b-d)i O Hints: return this; // return "this" instance O You are required to: Write Java code for the MyComplex class. Write a test driver class to test all public methods defined in question 1 (number 1 7). You do NOT need to implement other methods not specified in (1 7) Write an application called MyComplexApp that uses the MyComplex class. The application shall prompt the user to enter two complex numbers, print their values, check for real, imaginary and equality, and carry out all the arithmetic operations ( Add and Subtract) mentioned above. Sample test run Enter complex number 1 (real and imaginary part): 1.1 2.2 Enter complex number 2 (real and imaginary part): 3.3 4.4 Number 1 is: (1.1 + 2.2i) (1.1 + 2.2i) is NOT a pure real number (1.1 + 2.2i) is NOT a pure imaginary number Number 2 is: (3.3 + 4.4i) (3.3 + 4.4i) is NOT a pure real number (3.3 + 4.4i) is NOT a pure imaginary number
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