kann mir wer helfen?
ich komme einfach nicht auf die uhrsache des fehlers hier der code und fehlerausgabe wenn jemand was findet
Fehlerhafte Methode:
public boolean equals(Object other) {
if (this == other) return true;
if (!(other instanceof Polygon)) return false;
Polygon otherPolygon = (Polygon) other;
// Check if both polygons are empty
if (this.points.isEmpty() || otherPolygon.points.isEmpty()) {
return false;
}
// Check if the number of points is the same
if (this.points.size() != otherPolygon.points.size()) {
return false;
}
// Check if the points in the same order are equal
for (int i = 0; i < points.size(); i++) {
if (!this.points.get(i).equals(otherPolygon.points.get(i))) {
return false;
}
}
return true;
}
Main Methode:
package einfprog;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
// Test der Implementierung
// Testfall 1: Leeres Polygon sollte nicht gleich einem anderen leeren Polygon sein
ArrayList<Point> emptyPoints1 = new ArrayList<>();
ArrayList<Point> emptyPoints2 = new ArrayList<>();
Polygon emptyPolygon1 = new Trigon(emptyPoints1); // Verwende eine konkrete Implementierung wie Trigon
Polygon emptyPolygon2 = new Trigon(emptyPoints2); // Verwende eine konkrete Implementierung wie Trigon
System.out.println("Empty Polygon1: " + emptyPolygon1);
System.out.println("Empty Polygon2: " + emptyPolygon2);
System.out.println("Empty Polygon1 equals Empty Polygon2: " + emptyPolygon1.equals(emptyPolygon2)); // Erwartet false
System.out.println();
// Testfall 2: Trigon mit verschiedenen Punkten
ArrayList<Point> points3 = new ArrayList<>();
points3.add(new Point(1, 1));
points3.add(new Point(2, 2));
points3.add(new Point(3, 3));
Trigon trigon1 = new Trigon(points3);
System.out.println("Trigon1: " + trigon1);
System.out.println("Circumference: " + trigon1.getCircumference());
System.out.println("Area: " + trigon1.getArea());
System.out.println("Is Rectangle: " + trigon1.isRectangle());
}
}
Fehlermeldung:
Part 1 -- 10/11 tests passed: Point: Success Point.equals(): Success Point.getDistance(): Success Point.toString(): Success Polygon: Success Polygon.equals(): Failed: Expected true for [] and [], but was false Polygon.getCircumference(): Success Polygon.repair(): Success Polygon.clean(): Success Polygon.toString(): Success new Trigon(): Success
Java,
Code,
Fehlermeldung