home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / Chap08 / Test / srd / math / ComplexNumber.class (.txt)
Encoding:
Java Class File  |  1996-09-03  |  1020 b   |  27 lines

  1. package srd.math;
  2.  
  3. class ComplexNumber {
  4.    private double m_dReal;
  5.    private double m_dImag;
  6.  
  7.    public ComplexNumber Add(ComplexNumber cn) {
  8.       return new ComplexNumber(this.m_dReal + cn.m_dReal, this.m_dImag + cn.m_dImag);
  9.    }
  10.  
  11.    public ComplexNumber(double dR, double dI) {
  12.       this.m_dReal = dR;
  13.       this.m_dImag = dI;
  14.    }
  15.  
  16.    public ComplexNumber(double dR) {
  17.       this(dR, (double)0.0F);
  18.    }
  19.  
  20.    public String toString() {
  21.       StringBuffer sb = new StringBuffer();
  22.       sb.append('(').append(this.m_dReal).append(',');
  23.       sb.append(this.m_dImag).append(')');
  24.       return sb.toString();
  25.    }
  26. }
  27.