Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task in this project will be to fill in the template Complex.java. For this project we are concerned mainly with the arithmetic and algebraic properties

Task in this project will be to fill in the template Complex.java. For this project we are concerned mainly with the arithmetic and algebraic properties of complex numbers. Several common operations are defined below. Let z = a + bi and w = c + di be particular complex numbers.

Don't need the code to fully function, but it would be nice if it did. I just need a little push to start and get I'll get things going after. The code template is at the buttom so just copy and paste into an IDE or anywhere. Template just needs to be filled with code. The methods and constructors have directions on them on how they should run so hopefully it isn't to hard to do. Thanks in advance.

image text in transcribed

image text in transcribed

class Complex {

//--------------------------------------------------------------------------

// Private Data Fields

//--------------------------------------------------------------------------

private double re;

private double im;

//--------------------------------------------------------------------------

// Public Constant Fields

//--------------------------------------------------------------------------

public static final Complex ONE = Complex.valueOf(1,0);

public static final Complex ZERO = Complex.valueOf(0,0);

public static final Complex I = Complex.valueOf(0,1);

//--------------------------------------------------------------------------

// Constructors

//--------------------------------------------------------------------------

Complex(double a, double b){

this.re = a;

this.im = b;

}

Complex(double a){

this.re = a;

this.im = 0;

}

Complex(String s){

// Fill in this constructor.

// It should accept expressions like "-2+3i", "2-3i", "3", "5i", etc..

// Throw a NumberFormatException if s cannot be parsed as Complex.

}

//---------------------------------------------------------------------------

// Public methods

//---------------------------------------------------------------------------

// Complex arithmetic -------------------------------------------------------

Complex copy(){

// copy()

// Return a new Complex equal to this Complex

}

Complex add(Complex z){

// add()

// Return a new Complex representing the sum this plus z.

}

Complex negate(){

// negate()

// Return a new Complex representing the negative of this.

}

Complex sub(Complex z){

// sub()

// Return a new Complex representing the difference this minus z.

}

Complex mult(Complex z){

// mult()

// Return a new Complex representing the product this times z.

}

Complex recip(){

// recip()

// Return a new Complex representing the reciprocal of this.

// Throw an ArithmeticException with appropriate message if

// this.equals(Complex.ZERO).

}

Complex div(Complex z){

// div()

// Return a new Complex representing the quotient of this by z.

// Throw an ArithmeticException with appropriate message if

// z.equals(Complex.ZERO).

}

Complex conj(){

// conj()

// Return a new Complex representing the conjugate of this Complex.

}

double Re(){

// Re()

// Return the real part of this.

return re;

}

double Im(){

// Im()

// Return the imaginary part of this.

return im;

}

double abs(){

// abs()

// Return the modulus of this Complex, i.e. the distance between

// points (0, 0) and (re, im).

}

double arg(){

// arg()

// Return the argument of this Complex, i.e. the angle this Complex

// makes with positive real axis.

return Math.atan2(im, re);

}

// Other functions ---------------------------------------------------------

public String toString(){

// toString()

// Return a String representation of this Complex. The real and imaginary

// parts will be rounded to 8 decimal places, and trailing zeros will be

// truncated from the two parts. The String returned will be readable by

// the constructor Complex(String s)

}

public boolean equals(Object obj){

// equals()

// Return true iff this and obj have the same real and imaginary parts.

}

static Complex valueOf(double a, double b){

// valueOf()

// Return a new Complex with real part a and imaginary part b.

}

static Complex valueOf(double a){

// valueOf()

// Return a new Complex with real part a and imaginary part 0.

}

static Complex valueOf(String s){

// valueOf()

// Return a new Complex constructed from s.

}

}

Add: z+w-(a +c) + (b+d)i Subtract: z-w- (a -c) + (b-d) Multiply: zw-(ac- bd) +(ad +bc)i Reciprocal: -- Divide: ac+bdad-bc Conjugate: z-a-bi Real and Imaginary parts: Re(z)-a and Im(z)-b Absolute value (also called modulus): z = a2+b2 Argument: arg(2) the angle ? in the range -?

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