# Java代写 | Assignment Complex Number Objects

Java实现复杂数字演示

Write a Complex number class that will allow the main Complex Number Demonstration program to work correctly. It will need a default value constructor, and an explicit two parameter constructor:

Complex(),

Complex(double, double)’ //takes the real and imaginary parts of a complex number as arguments.

You will need the following methods:

subtract(Complex):Complex,

multiply(Complex):Complex,

divide(Complex):Complex.

You will also need to overload the equals(Object) method with an equals(Complex) method, and override the toString() method. Include get and set methods as well.

I will provide a main test program.

Note:

• Choose descriptive variable names: The a, b, c, and d markers used below are not acceptable variable names.
• You are not permitted to change the test program I provide. All of your changes must be made in the new class you provide.
• Remember to include your algorithms. This is a relatively easy program to code. You will need the explicit two parameter Complex number constructor to make a new complex object to return from the complex math methods.

Complex Number:

Consists of a Real part and an Imaginary part.

a + bi

Where “a” is the Real part and “bi” is the Imaginary part.

Where “a” and “b” are a Real-numbers, and “i” is defined as the square root of -1.

Complex Number math is just a form of Polynomial Math:

Given two complex numbers a + bi and c + di, the math algorithms are:

(a + bi) + (c + di) = (a + c) + (b + d)i

Subtraction:           Real     Imaginary

(a + bi) – (c + di) = (a – c) + (b – d)i

Multiplication:              Real              Imaginary

(a + bi) * (c + di) = (a * c) – (b * d) + ((a * d) + (b * c))i

Division:

a + bi  =  a + bi * c – di (Multiplying by 1)

c + di     c + di   c – di

(a * c) + (b * d) + (bi * c) – (a * di)

(c * c) – (di * di)

(a * c) + (b * d) + (b * i * c) – (a * d * i)

(c * c) – (d * i * d * i)

(a * c) + (b * d) + ((b * c) – (a * d))i

(c * c) – (d * d) *(i * i)

(a * c) + (b * d) + ((b * c) – (a * d))i

(c * c) – (d * d) *(-1) since sqrt -1 * sqrt -1 == -1

(a * c) + (b * d) + ((b * c) – (a * d))i

(c * c) + (d * d)

Real                 Imaginary

(a * c) + (b * d) + ((b * c) – (a * d))i  (Algorithm formula for division)

(c * c) + (d * d)    (c * c) + (d * d)

Example of the running of the Complex Number Demo:

This program will perform basic math on Complex numbers

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1

You input the following Complex numbers:

1.00 + 1.00i

1.00 + 1.00i

You may perform one of the following operations:

2. Subtract the first number from the second number
3. Subtract the second number from the first number
4. Multiplication
5. Divide the first number by the second number
6. Divide the second number by the first number
7. Check for Equality

7

Checking if 1.00 + 1.00i is equal to 1.00 + 1.00i

1.00 + 1.00i is equal to 1.00 + 1.00i

Would you like to enter new numbers?

yes

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

r

wrong input type

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1.0

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

d

wrong input type

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

4.5

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1

You input the following Complex numbers:

1.00 + 4.50i

1.00 + 1.00i

You may perform one of the following operations:

2. Subtract the first number from the second number
3. Subtract the second number from the first number
4. Multiplication
5. Divide the first number by the second number
6. Divide the second number by the first number
7. Check for Equality

2

Subtracting 1.00 + 4.50 from 1.00 + 1.00

Produces: 0.00 + -3.50i

Would you like to enter new numbers?

yes

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

2

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

3

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

4

You input the following Complex numbers:

1.00 + 2.00i

3.00 + 4.00i

You may perform one of the following operations:

2. Subtract the first number from the second number
3. Subtract the second number from the first number
4. Multiplication
5. Divide the first number by the second number
6. Divide the second number by the first number
7. Check for Equality

3

Subtracting 3.00 + 4.00i from 1.00 + 2.00i

Produces: -2.00 + -2.00i

Would you like to enter new numbers?

yes

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1.2

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

2.3

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

3.4

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

4.5

You input the following Complex numbers:

1.20 + 2.30i

3.40 + 4.50i

You may perform one of the following operations:

2. Subtract the first number from the second number
3. Subtract the second number from the first number
4. Multiplication
5. Divide the first number by the second number
6. Divide the second number by the first number
7. Check for Equality

4

Multiplying 1.20 + 2.30i by 3.40 + 4.50i

Produces: -6.27 + 13.22i

Would you like to enter new numbers?

yes

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1.2

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

2.3

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

3.4

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

4.5

You input the following Complex numbers:

1.20 + 2.30i

3.40 + 4.50i

You may perform one of the following operations:

2. Subtract the first number from the second number
3. Subtract the second number from the first number
4. Multiplication
5. Divide the first number by the second number
6. Divide the second number by the first number
7. Check for Equality

4

Multiplying 1.20 + 2.30i by 3.40 + 4.50i

Produces: -6.27 + 13.22i

Would you like to enter new numbers?

yes

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

1.2

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

2.3

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

3.4

This number may be positive or negative and may be an integer or a decimal number.

(e.g. 5, -5, 1.5, -1.5)

4.5

You input the following Complex numbers:

1.20 + 2.30i

3.40 + 4.50i

You may perform one of the following operations:

2. Subtract the first number from the second number
3. Subtract the second number from the first number
4. Multiplication
5. Divide the first number by the second number
6. Divide the second number by the first number
7. Check for Equality

6

Dividing 3.40 + 4.50i by 1.20 + 2.30i

Produces: 2.14 + -0.36i

Would you like to enter new numbers?

no

Goodbye!! E-mail: [email protected]  微信:itcsdx 