Subato

equals auf GeometricObject

Überschreiben Sie für die Klasse GeometricObject die Methode equals. Zwei Objekte sollen gleich sein, wenn einen gleichen Eckpunkt haben und sich Höhe und Weite maximal um 1 unterscheiden. Das Feld velocity wird dabei nicht betrachtet.

package name.panitz.oose; public class GeometricObject { Vertex corner; double width; double height; Vertex velocity; public GeometricObject(Vertex corner, double width, double height, Vertex velocity) { super(); this.corner = corner; this.width = width; this.height = height; this.velocity = velocity; } double size(){ return width*height; } public void move() { corner.x += velocity.x; corner.y += velocity.y; } @Override public String toString() { return corner+" "+width+" "+height; } boolean isLargerThan(GeometricObject that){ return size()>that.size(); } boolean isAbove(GeometricObject that){ return corner.y+height<that.corner.y; } boolean isUnderneath(GeometricObject that){ return that.isAbove(this); } boolean isLeftOf(GeometricObject that){ return corner.x+width<that.corner.x; } boolean isRightOf(GeometricObject that){ return that.isLeftOf(this); } boolean touches(GeometricObject that){ return !(isLeftOf(that)||isRightOf(that) ||isAbove(that)||isUnderneath(that)); } //TODO equals überschreiben }
java
You are not logged in and therefore you cannot submit a solution.