Tiefe Kopie

valentina2013

Bekanntes Mitglied
Hallo,

ich habe ein Verständnisproblem:

hier eine kalsse Complex
Java:
class Complex {

    private double real, imag;

	Complex() {}

	Complex(double real, double imag) {
		this.real = real;
		this.imag = imag;
	}

	Complex(Complex other) {
		this.real = other.real;
		this.imag = other.imag;
	}
public Complex add (Complex other) {
    	return new Complex();
	}

	public Complex sub (Complex other) {
		return new Complex();
	}

	public Complex mul (Complex other) {
		return new Complex();
	}

	public Complex div (Complex other) {
		return new Complex();
	}

	public Complex con () {
		return new Complex ();
	}
und hier die Texst Klasse:
Java:
public class TestComplex {

	public static void main(String args[]) {
	
		Complex a = new Complex(3, 4);
		Complex b = new Complex(2, 3);
		
		System.out.println(a.add(b));
		System.out.println(b.sub(a));
		System.out.println(a.mul(b));
		System.out.println(a.div(b));
		System.out.println(a.mul(a.con()));
		
	}
}
ich muss die entsprechende methoden implementieren und ich verstehe nicht ganz was da zurückgegebn wird mit return new Complex(). Weiss einer das?

danke 🙂
 
hi,
du sollst in den methoden das ergebnis berechnen und als komplexe zahl (objekt der klasse complex) zurückgeben. dieses wird in der jeweiligen methode erzeugt.
javampir
 
Es wird im Moment "nichts" zurück gegeben, es könnte auch "return null" da stehen.
Da die Member private sind brauchst du zusätzlich getter oder eine Ausgabemethode um die Zahlen darzustellen.
 

Zurück
Oben