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 9d7ecb6c authored by Dominikus Herzberg's avatar Dominikus Herzberg

Merge branch 'master' into 'dev-cs'

# Conflicts:
#   6.Vererbung.html
parents 15e8ec91 a487f13d
......@@ -653,7 +653,7 @@ false</pre>
<span class="local-variable">this</span>.x = x;
<span class="local-variable">this</span>.y = y;
}
<span class="directive">public</span> equals(<span class="predefined-type">Object</span> other) {
<span class="directive">public</span> <span class="type">boolean</span> equals(<span class="predefined-type">Object</span> other) {
<span class="keyword">if</span> (other <span class="keyword">instanceof</span> <span class="predefined-type">Point</span>) { <i class="conum" data-value="1"></i><b>(1)</b>
<span class="predefined-type">Point</span> otherPoint = (<span class="predefined-type">Point</span>) other; <i class="conum" data-value="2"></i><b>(2)</b>
<span class="keyword">return</span> otherPoint.x == <span class="local-variable">this</span>.x &amp;&amp; otherPoint.y == <span class="local-variable">this</span>.y;
......@@ -667,11 +667,12 @@ false</pre>
Car(<span class="type">double</span> tachometer) {
<span class="local-variable">this</span>.tachometer = tachometer;
}
<span class="directive">public</span> equals(<span class="predefined-type">Object</span> other) {
<span class="directive">public</span> <span class="type">boolean</span> equals(<span class="predefined-type">Object</span> other) {
<span class="keyword">if</span> (other <span class="keyword">instanceof</span> Car) { <i class="conum" data-value="1"></i><b>(1)</b>
Car otherCar = (Car) other; <i class="conum" data-value="2"></i><b>(2)</b>
<span class="keyword">return</span> otherCar.tachometer == <span class="local-variable">this</span>.tachometer;
}
<span class="keyword">return</span> <span class="predefined-constant">false</span>;
}
}
......@@ -686,7 +687,7 @@ false</pre>
<span class="local-variable">this</span>.numerator = numerator;
<span class="local-variable">this</span>.denominator = denominator;
}
<span class="directive">public</span> equals(<span class="predefined-type">Object</span> other) {
<span class="directive">public</span> <span class="type">boolean</span> equals(<span class="predefined-type">Object</span> other) {
<span class="keyword">if</span> (other <span class="keyword">instanceof</span> Fraction) { <i class="conum" data-value="1"></i><b>(1)</b>
Fraction otherFrac = (Fraction) other; <i class="conum" data-value="2"></i><b>(2)</b>
<span class="keyword">return</span> otherFrac.numerator == <span class="local-variable">this</span>.numerator
......@@ -694,7 +695,15 @@ false</pre>
}
<span class="keyword">return</span> <span class="predefined-constant">false</span>;
}
}</code></pre>
}
<span class="keyword">assert</span> !<span class="keyword">new</span> Fraction(<span class="integer">1</span>,<span class="integer">2</span>).equals(<span class="keyword">new</span> Car(<span class="float">123.0</span>));
<span class="keyword">assert</span> <span class="keyword">new</span> Fraction(<span class="integer">1</span>,<span class="integer">2</span>).equals(<span class="keyword">new</span> Fraction(<span class="integer">1</span>,<span class="integer">2</span>));
<span class="keyword">assert</span> <span class="keyword">new</span> Fraction(<span class="integer">2</span>).equals(<span class="keyword">new</span> Fraction(<span class="integer">2</span>,<span class="integer">1</span>));
<span class="keyword">assert</span> !<span class="keyword">new</span> Car(<span class="integer">12</span>).equals(<span class="keyword">new</span> Car(<span class="float">12.1</span>));
<span class="keyword">assert</span> <span class="keyword">new</span> Car(<span class="integer">12</span>).equals(<span class="keyword">new</span> Car(<span class="float">12.0</span>));
<span class="keyword">assert</span> !<span class="keyword">new</span> <span class="predefined-type">Point</span>(<span class="integer">3</span>,<span class="integer">4</span>).equals(<span class="keyword">new</span> <span class="predefined-type">Point</span>(<span class="integer">4</span>,<span class="integer">3</span>));
<span class="keyword">assert</span> <span class="keyword">new</span> <span class="predefined-type">Point</span>(<span class="integer">3</span>,<span class="integer">4</span>).equals(<span class="keyword">new</span> <span class="predefined-type">Point</span>(<span class="integer">3</span>,<span class="integer">4</span>));</code></pre>
</div>
</div>
<div class="colist arabic">
......
......@@ -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