GitLab wurde erfolgreich aktualisiert. Dank regelmäßiger Updates bleibt das THM GitLab sicher und Sie profitieren von den neuesten Funktionen. Danke für Ihre Geduld.

Commit f44096b2 authored by Dominikus Herzberg's avatar Dominikus Herzberg

"Lücken" im Code, return fehlte

parent 0502ca9a
......@@ -5,7 +5,7 @@ class Point {
this.x = x;
this.y = y;
}
public equals(Object other) {
public boolean equals(Object other) {
if (other instanceof Point) { // <1>
Point otherPoint = (Point) other; // <2>
return otherPoint.x == this.x && otherPoint.y == this.y;
......@@ -19,11 +19,12 @@ class Car {
Car(double tachometer) {
this.tachometer = tachometer;
}
public equals(Object other) {
public boolean equals(Object other) {
if (other instanceof Car) { // <1>
Car otherCar = (Car) other; // <2>
return otherCar.tachometer == this.tachometer;
}
return false;
}
}
......@@ -38,7 +39,7 @@ class Fraction {
this.numerator = numerator;
this.denominator = denominator;
}
public equals(Object other) {
public boolean equals(Object other) {
if (other instanceof Fraction) { // <1>
Fraction otherFrac = (Fraction) other; // <2>
return otherFrac.numerator == this.numerator
......@@ -46,4 +47,12 @@ class Fraction {
}
return false;
}
}
\ No newline at end of file
}
assert !new Fraction(1,2).equals(new Car(123.0));
assert new Fraction(1,2).equals(new Fraction(1,2));
assert new Fraction(2).equals(new Fraction(2,1));
assert !new Car(12).equals(new Car(12.1));
assert new Car(12).equals(new Car(12.0));
assert !new Point(3,4).equals(new Point(4,3));
assert new Point(3,4).equals(new Point(3,4));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment