Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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: o return this; // return "this" instance 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 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 +get Imag(): 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): My Complex +addNew(right:MyComplex): MyComplex +subtract(right:MyComplex): MyComplex +subtract New(right:MyComplex):MyComplex +multiply(right: MyComplex):MyComplex +divide(right: MyComplex):My Complex conjugate(): MyComplex 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 My Complex instance with the given real and imaginary values. 2. A default constructor that creates a MyComplex 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)

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions