Servus !
Ich habe für Hausaufgabe Theme Komplexe Zahlen und jetzt habe ich ein problem .
Ich habe der Code für Operationen so gemacht :
und wie rufe ich diese Operationen jetzt auf, dass wie auf diesem Bild sieht so aus :

Und kann ich des in dieser Code so verwenden ?
Und wie schreibe ich Funktion ,dass ich zwei nummer geben muss ?
Ich habe für Hausaufgabe Theme Komplexe Zahlen und jetzt habe ich ein problem .
Ich habe der Code für Operationen so gemacht :
Code:
public class Complex {
private double realTeil, imagTeil;
Complex(double realTeil, double imagTeil) {
this.realTeil = realTeil;
this.imagTeil = imagTeil;
}
double getRealTeil() {
return realTeil;
}
double getImagTeil() {
return imagTeil;
}
void set(double realTeil, double imagTeil) {
this.realTeil = realTeil;
this.imagTeil = imagTeil;
}
void add(Complex z) {
this.realTeil = this.realTeil + z.realTeil;
this.imagTeil = this.imagTeil + z.imagTeil;
}
public Complex plus(Complex z2) {
add(z2);
return this;
}
void subtract(Complex z) {
this.realTeil = this.realTeil - z.realTeil;
this.imagTeil = this.imagTeil - z.imagTeil;
}
public Complex minus(Complex z2) {
subtract(z2);
return this;
}
void multiply(Complex z) {
double r1 = this.realTeil;
double r2 = z.realTeil;
double i1 = this.imagTeil;
double i2 = z.imagTeil;
this.realTeil = (r1 * r2) - (i1 * i2);
this.imagTeil = (r1 * i2) + (i1 * r2);
}
public Complex multiplyWith(Complex z2) {
multiply(z2);
return this;
}
void divide(Complex z) {
double r1 = this.realTeil;
double r2 = z.realTeil;
double i1 = this.imagTeil;
double i2 = z.imagTeil;
double div = ((r2 * r2) + (i2 * i2));
this.realTeil = ((r1 * r2) + (i1 * i2)) / (div);
this.imagTeil = ((r1 * i2) - (i1 * r2)) / (div);
}
public Complex divideWith(Complex z2) {
divide(z2);
return this;
}
public double betrag() {
double r = this.realTeil;
double i = this.imagTeil;
return Math.sqrt((r * r) + (i * i));
}
@Override
public int hashCode() {
return Double.valueOf(realTeil).hashCode() * 31 + Double.valueOf(imagTeil).hashCode();
}
@Override
public boolean equals(Object obj) {
if(this == obj) {
return true;
}
if(obj instanceof Complex) {
Complex other = (Complex) obj;
return realTeil == other.realTeil && imagTeil == other.imagTeil;
}
return false;
}
@Override
public String toString() {
if (imagTeil == 0.0 || Double.isNaN(imagTeil)) {
return realTeil + "";
} else if (realTeil == 0.0 || Double.isNaN(realTeil)) {
return imagTeil + "i";
} else if (imagTeil < 0.0) {
return realTeil + " - " + (-imagTeil) + "i";
} else {
return realTeil + " + " + imagTeil + "i";
}
}
}
und wie rufe ich diese Operationen jetzt auf, dass wie auf diesem Bild sieht so aus :

Und kann ich des in dieser Code so verwenden ?
Code:
public class KomplexeZahlen {
public static void main (String[] args) {
Out.println("n - fur neue komplexe Zahl ");
Out.println("c - eine bestehende Zahl soll kopert werden ");
Out.println("a - fur eine Addition " ) ;
Out.println("s - fur eine Subtraktion ");
Out.println("m - fur eine Multiplikation");
Out.println("d - fur eine Division ");
Out.println("e - fur Ende");
char ch = 0; ;
while(ch != 'e') {
Out.println("---------------");
Out.print("Biite Operation eingeben : ");
ch = In.readChar();
Out.println("---------------");
if(ch == 'n') {
} else if(ch == 'c') {
} else if(ch == 'a') {
} else if(ch == 's') {
} else if(ch == 'm') {
} else if(ch == 'd') {
} else if(ch == 'e') {
}
}
}
}
Und wie schreibe ich Funktion ,dass ich zwei nummer geben muss ?
Zuletzt bearbeitet: