// zu UEBUNG 10 Aufgabe 2 public class Vector2D { public float v1; public float v2; public Vector2D(float a1, float a2) { v1 = a1; v2 = a2; } public void addInPlace(Vector2D other) { v1 += other.v1; v2 += other.v2; } public Vector2D add(Vector2D other) { // Man kann hier "this." auch weglassen, da das Objekt seine // eigenen Variablen v1,v2 kennt. Wenn v1 und v2 allerdings // noch einmal lokale Variablen innerhalb dieser Methode sind, // kann mit this.v1 explizit auf das in u10a2 "global" // deklarierte v1 referenziert werden. return new Vector2D(this.v1 + other.v1, this.v2 + other.v2); } public void normalize() { float abs = (float) Math.sqrt(v1 * v1 + v2 * v2); v1 /= abs; v2 /= abs; } public boolean equals(Vector2D other) { return (v1 == other.v1) && (v2 == other.v2); } }