Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the following UML diagram as a guide to write two classes to show arithmetic operations on complex number (objects). For this problem, you need

Use the following UML diagram as a guide to write two classes to show arithmetic operations on complex number (objects). For this problem, you need to track (count) the total number of complex objects created. Remember each complex number has two numbers (real, imaginary). All the numbers are of double type. To save some time, use the toString( ) method provided (at the end) to print complex numbers ( x, yi). Your result should look like the following:

The number of Complex objects: 2

c1: 2.5 - 4.3i

c2: -12.34 + 4.33i

Real part of c1: 2.5

Imaginary part of c1: -4.3

Testing Mutators - Updated c2: -4.0 + 3.0i

c1 magnitude: 4.973932046178355

c2 magnitude: 5.0

c3: 6.5i

c4: 2.5 - 4.3i

The number of Complex objects: 4

Test: c1==c4 => true

**** Complex Arithmetic test ****

c1 = 2.5 - 4.3i c2 = -4.0 + 3.0i

c1 + c2 = -1.5 - 1.2999999999999998i

c1 - c2 = 6.5 - 7.3i

c1 * c2 = 2.8999999999999986 + 24.7i

The number of Complex objects created: 7

// Textual Representation a + ci

public String toString() {

String s;

if (imaginary == 0.0)

s = "" + real;

else if (real == 0.0)

s = imaginary + "i";

else if (imaginary 0)

s = real + " - " + (-imaginary) + "i";

else

s = real + " + " + imaginary + "i";

return s;

}

}

image text in transcribed

> GComplex Assignment1 trial count: int0 Complex(double,double) Complex(double) Java Class>> G TestComplex Assignment1 trial o getReal):double TestComplex) e setReal(double)void setlmaginary(double) void o plus(Complex) Complex e minus(Complex) Complex times(double) Complex magnitude(Complex) double equals(Complex):boolean

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

Beginning PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions

Question

Why? What will be my payoff?

Answered: 1 week ago