diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-12-15 10:54:53 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-12-15 10:54:53 +0100 |
commit | a06d23a833fa99b83a89a51ee6c6f6e7269d41b1 (patch) | |
tree | 96902b937f8985fed970b6f1d9ccd984072f71fc /ws2015/eip/blaetter/08/de | |
parent | 872eb7d0094185271b3666cb93803f1f74f038bf (diff) | |
download | uni-a06d23a833fa99b83a89a51ee6c6f6e7269d41b1.tar uni-a06d23a833fa99b83a89a51ee6c6f6e7269d41b1.tar.gz uni-a06d23a833fa99b83a89a51ee6c6f6e7269d41b1.tar.bz2 uni-a06d23a833fa99b83a89a51ee6c6f6e7269d41b1.tar.xz uni-a06d23a833fa99b83a89a51ee6c6f6e7269d41b1.zip |
EiP - 08
Diffstat (limited to 'ws2015/eip/blaetter/08/de')
7 files changed, 146 insertions, 0 deletions
diff --git a/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Hund.java b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Hund.java new file mode 100644 index 0000000..8e86ace --- /dev/null +++ b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Hund.java | |||
@@ -0,0 +1,11 @@ | |||
1 | package de.lmu.ifi.tcs; | ||
2 | |||
3 | /** | ||
4 | * Created by jost on 08.12.15. | ||
5 | */ | ||
6 | public class Hund implements Tier { | ||
7 | @Override | ||
8 | public String gibLaut() { | ||
9 | return "Wau! Wau!"; | ||
10 | } | ||
11 | } | ||
diff --git a/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Hundeschule.java b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Hundeschule.java new file mode 100644 index 0000000..e802c6a --- /dev/null +++ b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Hundeschule.java | |||
@@ -0,0 +1,20 @@ | |||
1 | package de.lmu.ifi.tcs; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | |||
5 | /** | ||
6 | * Ein Beispiel, wie man es _nicht_ machen sollte! | ||
7 | * | ||
8 | * Created by jost on 08.12.15. | ||
9 | */ | ||
10 | public class Hundeschule extends ArrayList<Tier> { | ||
11 | |||
12 | @Override | ||
13 | public boolean add(Tier t){ | ||
14 | if (t.gibLaut().equals("Wau! Wau!")) | ||
15 | return super.add(t); | ||
16 | else | ||
17 | return false; | ||
18 | } | ||
19 | |||
20 | } | ||
diff --git a/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/HundeschuleKorrekt.java b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/HundeschuleKorrekt.java new file mode 100644 index 0000000..6fb527f --- /dev/null +++ b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/HundeschuleKorrekt.java | |||
@@ -0,0 +1,52 @@ | |||
1 | package de.lmu.ifi.tcs; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | import java.util.Iterator; | ||
5 | |||
6 | class HundeschuleKorrekt { | ||
7 | private ArrayList<Tier> roster; | ||
8 | |||
9 | public HundeschuleKorrekt() | ||
10 | { | ||
11 | roster = new ArrayList<Tier>(); | ||
12 | } | ||
13 | |||
14 | private static boolean isAdmissable(Tier tier) | ||
15 | { | ||
16 | if (tier.getClass().equals(Hund.class)) | ||
17 | return true; | ||
18 | return false; | ||
19 | } | ||
20 | |||
21 | public boolean add(Tier tier) | ||
22 | { | ||
23 | if (! isAdmissable(tier)) | ||
24 | return false; | ||
25 | return roster.add(tier); | ||
26 | } | ||
27 | |||
28 | public boolean addAll(ArrayList<Tier> tiere) | ||
29 | { // Ugh. | ||
30 | Iterator<Tier> it = roster.iterator(); | ||
31 | ArrayList<Tier> admissable = new ArrayList<Tier>(); | ||
32 | |||
33 | while (it.hasNext()) | ||
34 | { | ||
35 | Tier tier = it.next(); | ||
36 | if (isAdmissable(tier)) | ||
37 | admissable.add(tier); | ||
38 | } | ||
39 | |||
40 | return roster.addAll(admissable); | ||
41 | } | ||
42 | |||
43 | public boolean remove(Tier tier) | ||
44 | { | ||
45 | return roster.remove(tier); | ||
46 | } | ||
47 | |||
48 | public ArrayList<Tier> getTiere() | ||
49 | { | ||
50 | return roster; | ||
51 | } | ||
52 | } | ||
diff --git a/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Katze.java b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Katze.java new file mode 100644 index 0000000..0e20b72 --- /dev/null +++ b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Katze.java | |||
@@ -0,0 +1,12 @@ | |||
1 | package de.lmu.ifi.tcs; | ||
2 | |||
3 | /** | ||
4 | * Created by jost on 08.12.15. | ||
5 | */ | ||
6 | public class Katze implements Tier { | ||
7 | |||
8 | @Override | ||
9 | public String gibLaut() { | ||
10 | return "Miau!"; | ||
11 | } | ||
12 | } | ||
diff --git a/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Tier.java b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Tier.java new file mode 100644 index 0000000..fabd990 --- /dev/null +++ b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/Tier.java | |||
@@ -0,0 +1,8 @@ | |||
1 | package de.lmu.ifi.tcs; | ||
2 | |||
3 | /** | ||
4 | * Created by jost on 08.12.15. | ||
5 | */ | ||
6 | public interface Tier { | ||
7 | String gibLaut(); | ||
8 | } | ||
diff --git a/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/TierDemo.java b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/TierDemo.java new file mode 100644 index 0000000..3a3adfa --- /dev/null +++ b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/TierDemo.java | |||
@@ -0,0 +1,30 @@ | |||
1 | package de.lmu.ifi.tcs; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | |||
5 | public class TierDemo { | ||
6 | |||
7 | public static void main(String[] args) { | ||
8 | ArrayList<Tier> tiere = new ArrayList<Tier> (); | ||
9 | tiere.add(new Katze()); | ||
10 | tiere.add(new Hund()); | ||
11 | Hundeschule hundeschule = new Hundeschule(); | ||
12 | hundeschule.add(new Hund()); | ||
13 | hundeschule.add(new Katze()); | ||
14 | hundeschule.addAll(tiere); | ||
15 | for (Tier t : hundeschule) { | ||
16 | System.out.println(t.gibLaut()); | ||
17 | } | ||
18 | System.out.println("Test Teil 2:"); | ||
19 | HundeschuleKorrekt schule = new HundeschuleKorrekt(); | ||
20 | schule.add(new Hund()); | ||
21 | schule.add(new Katze()); | ||
22 | schule.add(new Hund()); | ||
23 | schule.add(new Katze()); | ||
24 | schule.addAll(tiere); | ||
25 | for (Tier t : schule.getTiere()) { | ||
26 | System.out.println(t.gibLaut()); | ||
27 | } | ||
28 | } | ||
29 | |||
30 | } | ||
diff --git a/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/TierSchule.java b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/TierSchule.java new file mode 100644 index 0000000..0d25738 --- /dev/null +++ b/ws2015/eip/blaetter/08/de/lmu/ifi/tcs/TierSchule.java | |||
@@ -0,0 +1,13 @@ | |||
1 | package de.lmu.ifi.tcs; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | |||
5 | /** | ||
6 | * Created by jost on 08.12.15. | ||
7 | */ | ||
8 | public interface TierSchule { | ||
9 | boolean add(Tier tier); | ||
10 | boolean remove(Tier tier); | ||
11 | boolean addAll(ArrayList<Tier> tiere); | ||
12 | ArrayList<Tier> getTiere(); | ||
13 | } | ||