Complex class

Complex class - A Java Class for Complex Numbers public...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Page 8-7 A Java Class for Complex Numbers public class Complex { private double u; private double v; //1a. Constructor to create a new complex number x+iy. Complex (double x, double y) {u=x; v=y;} //1b. Constructor to create a new complex number x+i0 where the imaginary component is zero. //Only the real component is used as an input argument. Complex (double x) {u=x; v=0; } //1c. The default constructor. Creates the new complex number 0+i0 Complex () {u=0; v=0; } //2a. Accessor method that returns the real part of a complex number. public double getReal () { return u;} //2b. Acessor method that returns the imaginary part of a complex number. public double getImaginary () {return v;} //3a. Mutator method that sets the real part of a complex number. public void setReal (double x) { u = x;} //3b. Mutator method that sets the imaginary part of a complex number. public void setImaginary (double y) { v = y;} //3c. Mutator method that sets both the real and imaginary parts of a complex number.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/17/2012 for the course ECE 203 taught by Professor Robincarr during the Fall '07 term at Drexel.

Ask a homework question - tutors are online