Answered step by step
Verified Expert Solution
Link Copied!

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:

image text in transcribed

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

=+How would it affect the trade deficit?

Answered: 1 week ago

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago

Question

=+ c. What happens to investment in Oceania?

Answered: 1 week ago