stefaniemayer088
Mitglied
ich wollte ein Klasse namens Complex für Komplexe ertellen:
Als Konstruktor wollte ich auch ein Konstruktor mit den Argumenten betrag und winkel. Leider das hat nix geklappt
Code:
import java.util.*;
class Complex {
// real
public double real;
// imag
public double imag;
public Complex(double myReal, double myImag) {
this.real = myReal;
this.imag = myImag;
}
public double getReal() {
return real;
}
public double getImag() {
return imag;
}
public String ausgabe(String iOderJ){
String erg=String.format(Locale.ENGLISH, "%+-1.3f%+-1.3f%s",
this.real,
this.imag,
iOderJ);
return erg;
}
}
Als Konstruktor wollte ich auch ein Konstruktor mit den Argumenten betrag und winkel. Leider das hat nix geklappt
Code:
import java.util.*;
class Complex {
// real
public double real;
// imag
public double imag;
public Complex(double myBetrag, double myWinkel) {
this.real = myBetrag*Math.cos(myWinkel);
this.imag =myBetrag*Math.sin(myWinkel);
}
public Complex(double myReal, double myImag) {
this.real = myReal;
this.imag = myImag;
}
public double getReal() {
return real;
}
public double getImag() {
return imag;
}
public String ausgabe(String iOderJ){
String erg=String.format(Locale.ENGLISH, "%+-1.3f%+-1.3f%s",
this.real,
this.imag,
iOderJ);
return erg;
}
}