public class Rectangle { // define the length and width as private private int a, b; // setter methods public void setA(int a) { if (a>=0) { // check for negative values this.a = a; } else { System.out.println("Fehler: Länge kann nicht negativ sein."); } } public void setB(int b) { if (b>=0) { // check for negative values this.b = b; } else { System.out.println("Fehler: Länge kann nicht negativ sein."); } } // Constructor public Rectangle(int a, int b) { setA(a); setB(b); } // Check if the length and width are identical public boolean isEqual(Rectangle rect) { if (this.a==rect.a && this.b==rect.b) { return true; } return false; } // main method to test some cases public static void main(String[] args) { // TODO Auto-generated method stub Rectangle myRect1 = new Rectangle(5,6); Rectangle myRect2 = new Rectangle(5,6); if (myRect1.isEqual(myRect2)) { System.out.println("Rechtecke sind gleich"); } else { System.out.println("Rechtecke sind verschieden"); } } }