Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

reate a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form realPart + imaginaryPart * i where i is square

reate a class called Complex for performing arithmetic with complex numbers. Complex

numbers have the form

realPart + imaginaryPart * i

where i is square root of -1

Use floating-point variables to represent the private data of the class. Provide a constructor that

enables an object of this class to be initialized when it is declared.

Provide a no-argument constructor with default values in case no initializers are provided.

Provide public methods that perform the following operations:

a) Add two Complex numbers: The real parts are added together and the imaginary parts are

added together. So, if we have (a + bi) + (c + di)), the result should be (a + c) + (b + d) i.

b) Subtract two Complex numbers: The real part of the right operand is subtracted from the real

part of the left operand, and the imaginary part of the right operand is subtracted from the

imaginary part of the left operand. So, if we have (a + bi) - (c + di)), the result should be (a - c)

+ (b - d) i.

c) Multiply two Complex numbers: The real part of the result is the real part of the right operand

multiplies the real part of the left operand minus the imaginary part of the right operand multiply

the imaginary part of the left operand. The imaginary part of the result is the real part of the left

operand multiply the imaginary part of the left operand plus the imaginary part of the left

operand multiply the real part of the right operand. So, if we have (a + bi) * (c + di)), the result

should be (ac - bd) + (ad + bc) i.

d) Division two Complex numbers: We set the value of square real part of the denominator plus

square imaginary part of the denominator is A. The real part of the result is the real part of the

numerator multiplies the real part of the denominator plus the imaginary part of the numerator

multiply the imaginary part of the denominator and divided by A. The imaginary part of the

Page

2

of

9

CISP401V11A4

result is the real part of the left operand multiply the imaginary part of the left operand plus the

imaginary part of the left operand multiply the real part of the right operand. So, if we have (a +

bi) / (c + di)), the result should be (ac+bd)+i(bc-ad))/(c

2

+d

2

).

e) Print Complex numbers in the form (a, b), where a is the real part and b is the imaginary part.

A public class (Complex as in this assignments demo programs) should be implemented to do

complex number calculation.

In the main function (ComplexTest as in the demo) you will instantiate two Complex class

objects, call Complex classs Addition, Subtraction, Multiply, Division function and print out the

result of the calculations.

The following are the specifications for this assignment.

Complex.java

There are two private double data members (real and imaginary). The real stores the real part of a

complex number and the imaginary stores the imaginary part of a complex number.

There are seven public functions (two Complex, add, subtract, multiply, division, and toString)

in this classes.

1. The first Complex function does not take any data. (or call no argument constructor) It

initializes 0s to the private data members.

2. The second Complex function takes two double numbers. (or call two-argument

constructor) It assigns the two numbers to the private data members.

3. The add function takes one Complex object and returns one Complex object. The

function does two complex numbers addition.

4. The subtract function takes one Complex object and returns one Complex object. The

function does two complex numbers subtraction.

5. The multiply function takes one Complex object and returns one Complex object. The

function does two complex numbers multiplication.

6. The division function takes one Complex object and returns one Complex object. The

function does two complex numbers division.

7. The toString function returns a String object but does not take any data. The function

returns a parenthesis string which represents complex number. The numbers are in

floating point format with only one digit after decimal point.

Page

3

of

9

CISP401V11A4

ComplexTest.java

It contains main function (driver) for this assignment. In the main function you have to do

1. Create two Complex objects with value of (9.5, 7.7) and (1.2, 3.1).

2. Print a proper formatted headline

A complex number in the form (x, y) is equal to x + yi,

where i is square root of -1.

3.

Print a second headline "*-Complex numbers calculations-*".

4.

If

an object contains (9.5, 7.7 ) and b object contains ( 1.2, 3.1 ). The program will use

System.out.printf function to display information by calling a.toString(), b.toString(), a.add( b

).toString(), a.subtract( b ).toString(),a.multiply( b ).toString(), and a.division( b ).toString() as

arguments.

You can fine the needed techniques in chapter 1~ 10. You can also use more advance skills

to do this assignment.

This assignment comes with a CISP401V11A4.zip file. It includes two files (ComplexTest.class and

Complex.class.) Both of the ComplexTest.class and Complex.class are executable files.

You can

place them in a sub folder (directory). Bring up a command prompt and go to the sub

directory, type java

ComplexTest

in the sub directory and hit Enter key. You should see

the program run and get to the result as the following picture. That should also be expecting

result of this assignment.

Please document the files properly and zip your

ComplexTest

.java and

Complex

.java files into a

proper named zip file for an assignment (refer to the assignment section of the class syllabus)

and submit it to the A4 folder of the Canvas Website.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions