2012-04-11 9 views
1

私はで何をしなければならないかを、このミッションを完了するために考える必要があると思います。 (申し訳ありませんが、私はプログラミングの初心者です)。Java Complex Numbers、3クラス

ファーストクラス;複素数のクラスを定義する。私はこれをかなり簡単に見つけ、私の答えは以下の通りです。

第2クラス;パブリック静的メソッドを使って加減算し、ファーストクラスから実数と虚数を想起する。この部分は、これを100%把握していないので少し挑戦的でした。

第3の部分は、ユーザーの入力を求めて、複素数のセットを加減算することです。私はユーザー入力を(0.0,0.0)形式で尋ねる必要がないので、これに慣れていません。

全体的なコードについての洞察はありますか?私は正しい軌道にいますか?

編集:

私が最初に学んだクラスです。皆さん、ありがとう。

2番目のクラス私は何かを完全に理解していないため、問題をコンパイルしています。

public class ComplexArith{ 
public static Complex add(Complex one, Complex two) 
{ 
return Complex(one.getReal() + two.getReal(), one.getImaginary() + two.getImaginary()); 
} 
public static Complex sub(Complex one, Complex two) 
{ 
return Complex(one.getReal() - two.getReal(), one.getImaginary - two.getImaginary()); 
} 
} 

私は1つと2つを定義する必要があることを知っていますが、それらを定義する方法を理解していません。私はそれらを何と定義しますか?私はそれが複合語クラスからdouble r、double iから呼び出されていると思った。

私はまた、.getImaginaryも第1クラスで定義されていると考えました。ここはファーストクラスです。

public class Complex 
{ 
private double real; 
private double imaginary; 

public Complex() 
{ 
    this(0.0, 0.0); 
} 


public Complex(double r, double i) 
{ 
    real = r; 
    imaginary = i; 
} 

public double getReal() { 
    return this.real; 
} 

public double getImaginary() { 
    return this.imaginary; 
} 
} 
+0

キーワードnew( 'return new Complex(...)')を使用して、タイプComplexのオブジェクトをインスタンス化します。それがコンストラクタ( 'public complex(double r、double i)')を呼び出すためのシグナルです。そして、 'getImaginary()'はメソッドシグネチャであり、 'getImaginary'ではありません。存在しない変数 – clwhisk

答えて

0

あなたは割り当てが何であるかを考えれば、正しい軌道に乗っています。

ただし、2番目のクラスではComplexオブジェクトのgetReal()getImaginary()メソッドを呼び出しています。しかし、その定義はComplexクラス定義のどこにも現れません。

ComplexArithのメソッドには戻り値の型がありません。

これらのみでは、コードがそのままコンパイルされることがなくなります。

+0

を参照しています。私はまもなくこの実現に着きました。 .getImaginaryと.getRealを私の最初のクラスに追加しましたが、まだコンパイルエラーが表示されています:シンボルを見つけることができません 戻り複合(one.getReal() - two.getReal()、one.getImaginary - two.getImaginary ()); ^ シンボル:変数getImaginary 場所:複合型の変数の1つ 2つのエラー 2つのエラーがさらに発生します。 – user1316703

+0

@ user1316703これは、あなたの 'sub'メソッドがgetImaginaryメソッド呼び出しのparanthesisを欠いているため、コンパイラが変数として解釈しようとしているからです。 'one.getImaginary'は' one.getImaginary() 'でなければなりません。 –

2

あなたは正しい方向にありますが、Complexオブジェクトにゲッターが必要です。例えば

public class Complex 
{ 
    private double real; 
    private double imaginary; 

    public Complex() 
    { 
     this(0.0, 0.0); 
    } 


    public Complex(double r, double i) 
    { 
     real = r; 
     imaginary = i; 
    } 

    public double getReal() { 
     return this.real; 
    } 

    public double getImaginary() { 
     return this.imaginary; 
    } 
} 

あなたはまた、あなたのメソッドの型を返す必要があります。

public class ComplexArith 
{ 
    public static Complex complexAdd(Complex one, Complex two) { 
     return Complex(one.getReal() + two.getReal(), 
         one.getImaginary() + two.getImaginary()); 
    } 

    public static Complex complexSub(Complex one, Complex two) { 
     return Complex(one.getReal() - two.getReal(), 
         one.getImaginary - two.getImaginary()); 
    } 
} 

はまた、それはあなたのプログラムの機能とは何の関係もありませんが、それはあなたが持っているのが通例ですメソッドはcamelCaseを使用します。したがって、あなたのメソッドは次のようになります:

public static Complex complexAdd(Complex one, Complex two) { 
    return Complex(one.getReal() + two.getReal(), 
        one.getImaginary() + two.getImaginary()); 
} 
+0

+1のためのcamelCaseの言及。最初はコンストラクタとしてメソッドを読みました。私は、何が起こっているかを追うために数回点滅しなければならなかった。 – Dave

+0

ああ、ありがとう。私は本当にフィードバックに感謝します。 私は何をする必要があるのか​​分かります(私の頭の中に良いフローチャートがあります)。私が必要とするものを達成するために必要なコードをよく知らないのです。コードをちょっと変えてみるつもりですが、私が解決したことを投稿します。 – user1316703

1

個人的には、これらの算術演算をComplexクラスに入れました。これらは本当に複素数での演算なので、複素数クラスの外にそれらをカプセル化しません。

私はComplexを不変にすることについて考えます。それはスレッドセーフな方法です。

私は静的なadd、sub、mul、divメソッドが好きです。彼らはコンプレックスを返すようにしてください(今はありません)。余弦、正弦などの他の方法は、複雑なパッケージのMathクラスに属している可能性があります。実数の例は、java.lang.Mathを参照してください。

「新しい複合体」を返す必要があります。あなたが書いたコードはコンパイルされません。 Complexにフォーマット(r,i)Stringを変換するため

+0

合意しましたが、割り当てが静的メソッドで2番目のクラスによって行われている場合は、OPはそれに固執しています。 – QuantumMechanic

+0

本当に、私の好みではない。私はそのようにしなければならないと主張したとしても、そうすることに反対しているだろう。良い理由を考えてみることをお勧めします。 – duffymo

+0

ええ、私はそれらにこだわっています。私は1つのクラスの中でそれをすべてやっていると、人生がもっと楽になると思うでしょう。 – user1316703

0

正しい方法は、正規表現を使用することです。しかし、あなたはあなたのインストラクターがあなたがインターネットからそのソリューションをコピーした疑いがあるかもしれません:)このような何かを試してみてくださいプログラミングに新しいしている場合:

public static Complex fromString(String str) { 
    str = str.substring(1, str.length() - 1); 
    String[] parts = str.split(","); 
    double r = Double.valueOf(parts[0]); 
    double i = Double.valueOf(parts[1]); 
    return new Complex(r, i); 
} 

あなたがここにJavaのStringクラスの詳細情報を見つけることができます:http://docs.oracle.com/javase/6/docs/api/java/lang/String.html

+0

私はすべてのコードを終えました。あなたが言及した問題に遭遇したと思います。複素数は出力時に読み取ることができません。しかし、あなたが書いたことは私には読めないほどです:D。正確には何が起こっていて、この変換はどのように機能していますか? – user1316703

+0

行ごとに:(1)最初と最後の括弧を取り除く、(2)真ん中のコンマで文字列を分割して、実数と虚数の2つの部分を得る(3-4)それらを倍に変換する、(5)新しい複合体を作る。また、System.out.println()を使用して複合体を印刷しようとしている場合は、このシグネチャを使用して複合体にメソッドを追加する必要があります:複合体の文字列表現を作成して返した 'public String toString()' 。 – cebarrett

1

これは私が1クラス上のすべてやる、私の実装です:

package name.puzio.math; 

public final class ComplexNumber { 
private final double imaginary; 
private final double real; 

@Override 
public final boolean equals(Object object) { 
    if (!(object instanceof ComplexNumber)) 
     return false; 
    ComplexNumber a = (ComplexNumber) object; 
    return (real == a.real) && (imaginary == a.imaginary); 
} 

public ComplexNumber(double real, double imaginary) { 
    this.imaginary = imaginary; 
    this.real = real; 
} 

public static final ComplexNumber createPolar(double amount, double angel) { 
    return new ComplexNumber(amount * Math.cos(angel), amount * Math.sin(angel)); 
} 

public final double getImaginary() { 
    return imaginary; 
} 

public final double getReal() { 
    return real; 
} 

public final double getAmount() { 
    return Math.sqrt((real * real) + (imaginary * imaginary)); 
} 

public final double getAngle() { 
    return Math.atan2(imaginary, real); 
} 

public final ComplexNumber add(ComplexNumber b) { 
    return add(this, b); 
} 

public final ComplexNumber sub(ComplexNumber b) { 
    return sub(this, b); 
} 

public final ComplexNumber div(ComplexNumber b) { 
    return div(this, b); 
} 

public final ComplexNumber mul(ComplexNumber b) { 
    return mul(this, b); 
} 

public final ComplexNumber conjugation() { 
    return conjugation(this); 
} 

/** 
* Addition: 
* @param a 
* @param b 
* @return 
*/ 
private final static ComplexNumber add(ComplexNumber a, ComplexNumber b) { 
    return new ComplexNumber(a.real + b.real, a.imaginary + b.imaginary); 
} 

/** 
* Subtraktion: 
* @param a 
* @param b 
* @return 
*/ 
private final static ComplexNumber sub(ComplexNumber a, ComplexNumber b) { 
    return new ComplexNumber(a.real - b.real, a.imaginary - b.imaginary); 
} 

/** 
* Multiplikation: 
* @param a 
* @param b 
* @return 
**/ 
private final static ComplexNumber mul(ComplexNumber a, ComplexNumber b) { 
    return new ComplexNumber((a.real * b.real) - (a.imaginary * b.imaginary), (a.imaginary * b.real) + (a.real * b.imaginary)); 
} 

/** 
* Division: 
* @param a 
* @param b 
* @return 
**/ 
private final static ComplexNumber div(ComplexNumber a, ComplexNumber b) { 
    double d = (b.real * b.real) + (b.imaginary * b.imaginary); 
    if (d == 0) 
     return new ComplexNumber(Double.NaN, Double.NaN); 
    return new ComplexNumber(((a.real * b.real) + (a.imaginary * b.imaginary))/d, ((a.imaginary * b.real) - (a.real * b.imaginary))/d); 
} 

/** 
* Konjugation: 
* @param a 
* @return 
**/ 

private final static ComplexNumber conjugation(ComplexNumber a) { 
    return new ComplexNumber(a.real, -a.imaginary); 
} 
} 
0

これはすでに私は人々が複素数に関連する機能の多くを行い、以下のクラスによって利益を得ることができると思った回答されてますが。

これはMITライセンスで公開されており、GitHubプロジェクトはhereです。

/** 
* <code>ComplexNumber</code> is a class which implements complex numbers in Java. 
* It includes basic operations that can be performed on complex numbers such as, 
* addition, subtraction, multiplication, conjugate, modulus and squaring. 
* The data type for Complex Numbers. 
* <br /><br /> 
* The features of this library include:<br /> 
* <ul> 
* <li>Arithmetic Operations (addition, subtraction, multiplication, division)</li> 
* <li>Complex Specific Operations - Conjugate, Inverse, Absolute/Magnitude, Argument/Phase</li> 
* <li>Trigonometric Operations - sin, cos, tan, cot, sec, cosec</li> 
* <li>Mathematical Functions - exp</li> 
* <li>Complex Parsing of type x+yi</li> 
* </ul> 
* 
* @author  Abdul Fatir 
* @version  1.1 
* 
*/ 
public class ComplexNumber 
{ 
    /** 
    * Used in <code>format(int)</code> to format the complex number as x+yi 
    */ 
    public static final int XY = 0; 
    /** 
    * Used in <code>format(int)</code> to format the complex number as R.cis(theta), where theta is arg(z) 
    */ 
    public static final int RCIS = 1; 
    /** 
    * The real, Re(z), part of the <code>ComplexNumber</code>. 
    */ 
    private double real; 
    /** 
    * The imaginary, Im(z), part of the <code>ComplexNumber</code>. 
    */ 
    private double imaginary; 
    /** 
    * Constructs a new <code>ComplexNumber</code> object with both real and imaginary parts 0 (z = 0 + 0i). 
    */ 
    public ComplexNumber() 
    { 
     real = 0.0; 
     imaginary = 0.0; 
    } 

    /** 
    * Constructs a new <code>ComplexNumber</code> object. 
    * @param real the real part, Re(z), of the complex number 
    * @param imaginary the imaginary part, Im(z), of the complex number 
    */ 

    public ComplexNumber(double real, double imaginary) 
    { 
     this.real = real; 
     this.imaginary = imaginary; 
    } 

    /** 
    * Adds another <code>ComplexNumber</code> to the current complex number. 
    * @param z the complex number to be added to the current complex number 
    */ 

    public void add(ComplexNumber z) 
    { 
     set(add(this,z)); 
    } 

    /** 
    * Subtracts another <code>ComplexNumber</code> from the current complex number. 
    * @param z the complex number to be subtracted from the current complex number 
    */ 

    public void subtract(ComplexNumber z) 
    { 
     set(subtract(this,z)); 
    } 

    /** 
    * Multiplies another <code>ComplexNumber</code> to the current complex number. 
    * @param z the complex number to be multiplied to the current complex number 
    */ 

    public void multiply(ComplexNumber z) 
    { 
     set(multiply(this,z)); 
    } 
    /** 
    * Divides the current <code>ComplexNumber</code> by another <code>ComplexNumber</code>. 
    * @param z the divisor 
    */ 
    public void divide(ComplexNumber z) 
    { 
     set(divide(this,z)); 
    } 
    /** 
    * Sets the value of current complex number to the passed complex number. 
    * @param z the complex number 
    */ 
    public void set(ComplexNumber z) 
    { 
     this.real = z.real; 
     this.imaginary = z.imaginary; 
    } 
    /** 
    * Adds two <code>ComplexNumber</code>. 
    * @param z1 the first <code>ComplexNumber</code>. 
    * @param z2 the second <code>ComplexNumber</code>. 
    * @return the resultant <code>ComplexNumber</code> (z1 + z2). 
    */ 
    public static ComplexNumber add(ComplexNumber z1, ComplexNumber z2) 
    { 
     return new ComplexNumber(z1.real + z2.real, z1.imaginary + z2.imaginary); 
    } 

    /** 
    * Subtracts one <code>ComplexNumber</code> from another. 
    * @param z1 the first <code>ComplexNumber</code>. 
    * @param z2 the second <code>ComplexNumber</code>. 
    * @return the resultant <code>ComplexNumber</code> (z1 - z2). 
    */ 
    public static ComplexNumber subtract(ComplexNumber z1, ComplexNumber z2) 
    { 
     return new ComplexNumber(z1.real - z2.real, z1.imaginary - z2.imaginary); 
    } 
    /** 
    * Multiplies one <code>ComplexNumber</code> to another. 
    * @param z1 the first <code>ComplexNumber</code>. 
    * @param z2 the second <code>ComplexNumber</code>. 
    * @return the resultant <code>ComplexNumber</code> (z1 * z2). 
    */ 
    public static ComplexNumber multiply(ComplexNumber z1, ComplexNumber z2) 
    { 
     double _real = z1.real*z2.real - z1.imaginary*z2.imaginary; 
     double _imaginary = z1.real*z2.imaginary + z1.imaginary*z2.real; 
     return new ComplexNumber(_real,_imaginary); 
    } 
    /** 
    * Divides one <code>ComplexNumber</code> by another. 
    * @param z1 the first <code>ComplexNumber</code>. 
    * @param z2 the second <code>ComplexNumber</code>. 
    * @return the resultant <code>ComplexNumber</code> (z1/z2). 
    */  
    public static ComplexNumber divide(ComplexNumber z1, ComplexNumber z2) 
    { 
     ComplexNumber output = multiply(z1,z2.conjugate()); 
     double div = Math.pow(z2.mod(),2); 
     return new ComplexNumber(output.real/div,output.imaginary/div); 
    } 

    /** 
    * The complex conjugate of the current complex number. 
    * @return a <code>ComplexNumber</code> object which is the conjugate of the current complex number 
    */ 

    public ComplexNumber conjugate() 
    { 
     return new ComplexNumber(this.real,-this.imaginary); 
    } 

    /** 
    * The modulus, magnitude or the absolute value of current complex number. 
    * @return the magnitude or modulus of current complex number 
    */ 

    public double mod() 
    { 
     return Math.sqrt(Math.pow(this.real,2) + Math.pow(this.imaginary,2)); 
    } 

    /** 
    * The square of the current complex number. 
    * @return a <code>ComplexNumber</code> which is the square of the current complex number. 
    */ 

    public ComplexNumber square() 
    { 
     double _real = this.real*this.real - this.imaginary*this.imaginary; 
     double _imaginary = 2*this.real*this.imaginary; 
     return new ComplexNumber(_real,_imaginary); 
    } 
    /** 
    * @return the complex number in x + yi format 
    */ 
    @Override 
    public String toString() 
    { 
     String re = this.real+""; 
     String im = ""; 
     if(this.imaginary < 0) 
      im = this.imaginary+"i"; 
     else 
      im = "+"+this.imaginary+"i"; 
     return re+im; 
    } 
    /** 
    * Calculates the exponential of the <code>ComplexNumber</code> 
    * @param z The input complex number 
    * @return a <code>ComplexNumber</code> which is e^(input z) 
    */ 
    public static ComplexNumber exp(ComplexNumber z) 
    { 
     double a = z.real; 
     double b = z.imaginary; 
     double r = Math.exp(a); 
     a = r*Math.cos(b); 
     b = r*Math.sin(b); 
     return new ComplexNumber(a,b); 
    } 
    /** 
    * Calculates the <code>ComplexNumber</code> to the passed integer power. 
    * @param z The input complex number 
    * @param power The power. 
    * @return a <code>ComplexNumber</code> which is (z)^power 
    */ 
    public static ComplexNumber pow(ComplexNumber z, int power) 
    { 
     ComplexNumber output = new ComplexNumber(z.getRe(),z.getIm()); 
     for(int i = 1; i < power; i++) 
     { 
      double _real = output.real*z.real - output.imaginary*z.imaginary; 
      double _imaginary = output.real*z.imaginary + output.imaginary*z.real; 
      output = new ComplexNumber(_real,_imaginary); 
     } 
     return output; 
    } 
    /** 
    * Calculates the sine of the <code>ComplexNumber</code> 
    * @param z the input complex number 
    * @return a <code>ComplexNumber</code> which is the sine of z. 
    */ 
    public static ComplexNumber sin(ComplexNumber z) 
    { 
     double x = Math.exp(z.imaginary); 
     double x_inv = 1/x; 
     double r = Math.sin(z.real) * (x + x_inv)/2; 
     double i = Math.cos(z.real) * (x - x_inv)/2; 
     return new ComplexNumber(r,i); 
    } 
    /** 
    * Calculates the cosine of the <code>ComplexNumber</code> 
    * @param z the input complex number 
    * @return a <code>ComplexNumber</code> which is the cosine of z. 
    */ 
    public static ComplexNumber cos(ComplexNumber z) 
    { 
     double x = Math.exp(z.imaginary); 
     double x_inv = 1/x; 
     double r = Math.cos(z.real) * (x + x_inv)/2; 
     double i = -Math.sin(z.real) * (x - x_inv)/2; 
     return new ComplexNumber(r,i); 
    } 
    /** 
    * Calculates the tangent of the <code>ComplexNumber</code> 
    * @param z the input complex number 
    * @return a <code>ComplexNumber</code> which is the tangent of z. 
    */ 
    public static ComplexNumber tan(ComplexNumber z) 
    { 
     return divide(sin(z),cos(z)); 
    } 
    /** 
    * Calculates the co-tangent of the <code>ComplexNumber</code> 
    * @param z the input complex number 
    * @return a <code>ComplexNumber</code> which is the co-tangent of z. 
    */ 
    public static ComplexNumber cot(ComplexNumber z) 
    { 
     return divide(new ComplexNumber(1,0),tan(z)); 
    } 
    /** 
    * Calculates the secant of the <code>ComplexNumber</code> 
    * @param z the input complex number 
    * @return a <code>ComplexNumber</code> which is the secant of z. 
    */ 
    public static ComplexNumber sec(ComplexNumber z) 
    { 
     return divide(new ComplexNumber(1,0),cos(z)); 
    } 
    /** 
    * Calculates the co-secant of the <code>ComplexNumber</code> 
    * @param z the input complex number 
    * @return a <code>ComplexNumber</code> which is the co-secant of z. 
    */ 
    public static ComplexNumber cosec(ComplexNumber z) 
    { 
     return divide(new ComplexNumber(1,0),sin(z)); 
    } 
    /** 
    * The real part of <code>ComplexNumber</code> 
    * @return the real part of the complex number 
    */ 
    public double getRe() 
    { 
     return this.real; 
    } 
    /** 
    * The imaginary part of <code>ComplexNumber</code> 
    * @return the imaginary part of the complex number 
    */ 
    public double getIm() 
    { 
     return this.imaginary; 
    } 
    /** 
    * The argument/phase of the current complex number. 
    * @return arg(z) - the argument of current complex number 
    */ 
    public double getArg() 
    { 
     return Math.atan2(imaginary,real); 
    } 
    /** 
    * Parses the <code>String</code> as a <code>ComplexNumber</code> of type x+yi. 
    * @param s the input complex number as string 
    * @return a <code>ComplexNumber</code> which is represented by the string. 
    */ 
    public static ComplexNumber parseComplex(String s) 
    { 
     s = s.replaceAll(" ",""); 
     ComplexNumber parsed = null; 
     if(s.contains(String.valueOf("+")) || (s.contains(String.valueOf("-")) && s.lastIndexOf('-') > 0)) 
     { 
      String re = ""; 
      String im = ""; 
      s = s.replaceAll("i",""); 
      s = s.replaceAll("I",""); 
      if(s.indexOf('+') > 0) 
      { 
       re = s.substring(0,s.indexOf('+')); 
       im = s.substring(s.indexOf('+')+1,s.length()); 
       parsed = new ComplexNumber(Double.parseDouble(re),Double.parseDouble(im)); 
      } 
      else if(s.lastIndexOf('-') > 0) 
      { 
       re = s.substring(0,s.lastIndexOf('-')); 
       im = s.substring(s.lastIndexOf('-')+1,s.length()); 
       parsed = new ComplexNumber(Double.parseDouble(re),-Double.parseDouble(im)); 
      } 
     } 
     else 
     { 
      // Pure imaginary number 
      if(s.endsWith("i") || s.endsWith("I")) 
      { 
       s = s.replaceAll("i",""); 
       s = s.replaceAll("I",""); 
       parsed = new ComplexNumber(0, Double.parseDouble(s)); 
      } 
      // Pure real number 
      else 
      { 
       parsed = new ComplexNumber(Double.parseDouble(s),0); 
      } 
     } 
     return parsed; 
    } 
    /** 
    * Checks if the passed <code>ComplexNumber</code> is equal to the current. 
    * @param z the complex number to be checked 
    * @return true if they are equal, false otherwise 
    */ 
    @Override 
    public final boolean equals(Object z) 
    { 
     if (!(z instanceof ComplexNumber)) 
      return false; 
     ComplexNumber a = (ComplexNumber) z; 
     return (real == a.real) && (imaginary == a.imaginary); 
    } 
    /** 
    * The inverse/reciprocal of the complex number. 
    * @return the reciprocal of current complex number. 
    */ 
    public ComplexNumber inverse() 
    { 
     return divide(new ComplexNumber(1,0),this); 
    } 
    /** 
    * Formats the Complex number as x+yi or r.cis(theta) 
    * @param format_id the format ID <code>ComplexNumber.XY</code> or <code>ComplexNumber.RCIS</code>. 
    * @return a string representation of the complex number 
    * @throws IllegalArgumentException if the format_id does not match. 
    */ 
    public String format(int format_id) throws IllegalArgumentException 
    { 
     String out = ""; 
     if(format_id == XY) 
      out = toString(); 
     else if(format_id == RCIS) 
     { 
      out = mod()+" cis("+getArg()+")"; 
     } 
     else 
     { 
      throw new IllegalArgumentException("Unknown Complex Number format."); 
     } 
     return out; 
    } 
} 
-1

これは間違っています。

public static ComplexNumber exp(ComplexNumber z) 
{ 
    double a = z.real; 
    double b = z.imaginary; 
    double r = Math.exp(a); 
    a = r*Math.cos(b); 
    b = r*Math.sin(b); 
    return new ComplexNumber(a,b); 
} 

あなたはこのナンセンスのすべてを省略し、ちょうどここで何よりも良い作品を必須含んはApache Commonsのライブラリを、使用することができます.......

public static ComplexNumber exp(ComplexNumber z) 
{ 
    double theta = Math.atan2(r.real/r.imag); 
    double r = mod(); 
    double a = r*Math.cos(theta); 
    double b = r*Math.sin(theta); 
    return new ComplexNumber(a,b); 
} 
+0

誰が無知なdownvoterだったのですか? –