sdgasdgasdg
parent
28e61e73e5
commit
40cc55f6e2
|
@ -1,5 +1,18 @@
|
|||
package pr2.vererbung.ueberladen_summe;
|
||||
|
||||
public class Summator {
|
||||
|
||||
public int sum(int a, int b) {
|
||||
return a+b;
|
||||
}
|
||||
public int sum(int a, int b, int c) {
|
||||
return a+b+c;
|
||||
}
|
||||
public int sum(int a, int b, int c, int d) {
|
||||
return a+b+c+d;
|
||||
}
|
||||
public int sum(int a, int b, int c, int d, int e) {
|
||||
return a+b+c+d+e;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,14 +10,14 @@ public class SummatorTest {
|
|||
@Test
|
||||
void testSum() {
|
||||
// TODO: Einkommentieren
|
||||
// Summator s = new Summator();
|
||||
// assertEquals(3, s.sum(1, 2));
|
||||
// assertEquals(1, s.sum(-1, 2));
|
||||
// assertEquals(6, s.sum(1, 2, 3));
|
||||
// assertEquals(0, s.sum(1, 2, -3));
|
||||
// assertEquals(10, s.sum(1, 2, 3, 4));
|
||||
// assertEquals(2, s.sum(1, 2, 3, -4));
|
||||
// assertEquals(15, s.sum(1, 2, 3, 4, 5));
|
||||
// assertEquals(5, s.sum(1, 2, 3, 4, -5));
|
||||
Summator s = new Summator();
|
||||
assertEquals(3, s.sum(1, 2));
|
||||
assertEquals(1, s.sum(-1, 2));
|
||||
assertEquals(6, s.sum(1, 2, 3));
|
||||
assertEquals(0, s.sum(1, 2, -3));
|
||||
assertEquals(10, s.sum(1, 2, 3, 4));
|
||||
assertEquals(2, s.sum(1, 2, 3, -4));
|
||||
assertEquals(15, s.sum(1, 2, 3, 4, 5));
|
||||
assertEquals(5, s.sum(1, 2, 3, 4, -5));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package pr2.vererbung.ueberschreiben_lebewesen;
|
||||
|
||||
public class Amoebe {
|
||||
public class Amoebe extends Lebewesen {
|
||||
|
||||
@Override
|
||||
public void bewegen() {
|
||||
System.out.println("schleimen");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package pr2.vererbung.ueberschreiben_lebewesen;
|
||||
|
||||
public class Dackel {
|
||||
public class Dackel extends Lebewesen{
|
||||
|
||||
@Override
|
||||
public void bewegen() {
|
||||
System.out.println("Auf kurzen Beinen vorwärts wackeln");
|
||||
|
||||
}
|
||||
|
||||
public void bellen() {
|
||||
System.out.println("wau wau wau");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package pr2.vererbung.ueberschreiben_lebewesen;
|
||||
|
||||
public class Lebewesen {
|
||||
public abstract class Lebewesen {
|
||||
|
||||
public abstract void bewegen();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,15 @@ package pr2.vererbung.ueberschreiben_lebewesen;
|
|||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO: Lebewesen testen
|
||||
Lebewesen l1 = new Dackel();
|
||||
Lebewesen l2 = new Amoebe();
|
||||
|
||||
l1.bewegen();
|
||||
l2.bewegen();
|
||||
|
||||
if (l1 instanceof Dackel) {
|
||||
Dackel dackel = (Dackel) l1;
|
||||
dackel.bellen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue