クラスを実装する必要がありComplexNumberます。2 つのジェネリック パラメータTとがありU、これは Number クラスを継承する何らかのクラスからのものでなければなりません。Complex クラスには、実部と虚部の 2 つのフィールド (インスタンス変数) があり、これらのメソッドを実装する必要があります。
ComplexNumber(T real, U imaginary)- コンストラクターgetReal():TgetImaginary():Umodul():double- これは複素数のモジュラスですcompareTo(ComplexNumber<?, ?> o)- このメソッドは、2 つの複素数のモジュラスに基づいて比較を行います
compareToこれらのワイルドカードを操作する方法がわからないため、最後のメソッドを除くすべてのメソッドを実装しました。
ここに私のコードがあります: ここでヘルプ - ペーストビン
class ComplexNumber <T extends Number,U extends Number> implements Comparable<ComplexNumber> {
private T real;
private U imaginary;
public ComplexNumber(T real, U imaginary) {
super();
this.real = real;
this.imaginary = imaginary;
}
public T getR() {
return real;
}
public U getI() {
return imaginary;
}
public double modul(){
return Math.sqrt(Math.pow(real.doubleValue(),2)+ Math.pow(imaginary.doubleValue(), 2));
}
public int compareTo(ComplexNumber<?, ?> o){
//HELP HERE
}
}
この方法を手伝ってくれる人はいますか?