For a (homework) project, I have a class ComplexNumber that needs to be printed. I have a number of operations that can be done on objects of the class (addition, subtraction, multiplication, division). Each operation returns a new ComplexNumber to be printed. How exactly do I print this? Do I have to write a special constructor or operator to print this in the format I want it? Here is an example of one method.
//code to select the addition case case 'a': System.out.println("Please enter the two complex numbers to be other in the form 7i+5j, separated by a whitespace"); base = getComplex(); other = getComplex(); System.out.println("The addition of numbers " + base + " and " + other + " is " + addition(base, other)); break; //the addition method public static ComplexNumber addition(ComplexNumber cmplx1, ComplexNumber cmplx2) { return new ComplexNumber(cmplx1.i + cmplx2.i, cmplx1.j + cmplx2.j); }In other words, how do I print a 'ComplexNumber'? Thanks.
This should be of help: http://en.literateprograms.org/Complex_numbers_(Java)
DavidKroukamp
Practically a Master Poster
Team Colleague
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169