Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 0.62 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. public class Complex {
  3.  
  4.         double re;
  5.         double im;
  6.        
  7.         public Complex(double x0, double y0)
  8.         {
  9.                 re = x0;
  10.                 im = y0;
  11.         }
  12.        
  13.          public double abs()   { return Math.hypot(re, im); }
  14.          
  15.          public Complex times(Complex b) {
  16.                 Complex a = this;
  17.                 double real = a.re * b.re - a.im * b.im;
  18.                 double imag = a.re * b.im + a.im * b.re;
  19.                 return new Complex(real, imag);
  20.             }
  21.          
  22.          public Complex plus(Complex b) {
  23.                 Complex a = this;             // invoking object
  24.                 double real = a.re + b.re;
  25.                 double imag = a.im + b.im;
  26.                 return new Complex(real, imag);
  27.             }
  28. }