From 7af662d37c7666788dce4d7b23f37b0b1e45fb8e Mon Sep 17 00:00:00 2001 From: Thomas Smits Date: Sat, 18 Feb 2023 15:46:46 +0100 Subject: [PATCH] Updated examples --- README.md | 19 ++ src/main/java/pr2/ads/adt/BinaryTree.java | 2 +- src/main/java/pr2/ads/adt/Queue.java | 2 +- src/main/java/pr2/ads/adt/QueueException.java | 2 +- src/main/java/pr2/ads/adt/Stack.java | 2 +- src/main/java/pr2/ads/adt/StackException.java | 2 +- src/main/java/pr2/ads/adt/TreeNode.java | 2 +- .../java/pr2/ads/searching/BinarySearch.java | 2 +- .../java/pr2/ads/searching/LinearSearch.java | 2 +- src/main/java/pr2/ads/searching/Searcher.java | 2 +- .../java/pr2/ads/searching/TestSearch.java | 2 +- .../pr2/ads/shuffle/FisherYatesShuffle.java | 2 +- .../java/pr2/ads/shuffle/NaiveShuffle.java | 2 +- src/main/java/pr2/ads/shuffle/Shuffler.java | 2 +- .../java/pr2/ads/shuffle/TestShuffle.java | 2 +- src/main/java/pr2/ads/sorting/BubbleSort.java | 2 +- .../java/pr2/ads/sorting/InsertionSort.java | 2 +- src/main/java/pr2/ads/sorting/MergeSort.java | 2 +- src/main/java/pr2/ads/sorting/QuickSort.java | 2 +- .../java/pr2/ads/sorting/SelectionSort.java | 2 +- src/main/java/pr2/ads/sorting/Sorter.java | 2 +- .../java/pr2/ads/sorting/TestSorting.java | 4 +- .../ads/textsearch/BoyerMooreTextSearch.java | 2 +- .../ads/textsearch/BruteForceTextSearch.java | 2 +- .../pr2/ads/textsearch/KMPTextSearch.java | 2 +- .../pr2/ads/textsearch/TestTextSearch.java | 2 +- .../java/pr2/ads/textsearch/TextSearch.java | 2 +- .../algorithmen/searching/BinarySearch.java | 23 +++ .../algorithmen/searching/LinearSearch.java | 14 ++ .../pr2/algorithmen/searching/Searcher.java | 8 + .../pr2/algorithmen/searching/TestSearch.java | 27 +++ .../shuffle/FisherYatesShuffle.java | 18 ++ .../pr2/algorithmen/shuffle/NaiveShuffle.java | 28 +++ .../pr2/algorithmen/shuffle/Shuffler.java | 12 ++ .../pr2/algorithmen/shuffle/TestShuffle.java | 20 +++ .../pr2/algorithmen/sorting/BubbleSort.java | 24 +++ .../algorithmen/sorting/InsertionSort.java | 28 +++ .../pr2/algorithmen/sorting/MergeSort.java | 46 +++++ .../pr2/algorithmen/sorting/QuickSort.java | 47 +++++ .../algorithmen/sorting/SelectionSort.java | 26 +++ .../java/pr2/algorithmen/sorting/Sorter.java | 12 ++ .../pr2/algorithmen/sorting/TestSorting.java | 73 ++++++++ .../textsearch/BoyerMooreTextSearch.java | 49 +++++ .../textsearch/BruteForceTextSearch.java | 22 +++ .../algorithmen/textsearch/KMPTextSearch.java | 46 +++++ .../textsearch/TestTextSearch.java | 21 +++ .../algorithmen/textsearch/TextSearch.java | 8 + src/main/java/pr2/ausnahmen/Java7.java | 2 +- .../pr2/ausnahmen/callstack/CallStack1.java | 2 +- .../pr2/ausnahmen/callstack/CallStack2.java | 2 +- .../pr2/ausnahmen/callstack/CallStack3.java | 2 +- .../ausnahmen/callstack/HandleOrDeclare.java | 2 +- .../java/pr2/ausnahmen/eigene/Client.java | 2 +- .../java/pr2/ausnahmen/eigene/Server.java | 2 +- .../pr2/ausnahmen/eigene/ServerException.java | 2 +- .../pr2/ausnahmen/eigene/SimpleExample2.java | 2 +- .../pr2/ausnahmen/eigene/SimpleExamples.java | 2 +- .../finall/TryCatchFinallyExample.java | 2 +- .../finall/TryCatchFinallyExample2.java | 2 +- .../java/pr2/ausnahmen/junit/BrokenTest.java | 2 +- .../pr2/ausnahmen/junit/TestMitExpected.java | 2 +- .../pr2/ausnahmen/junit/TestMitTryCatch.java | 2 +- src/main/java/pr2/ausnahmen/quiz/Finally.java | 2 +- .../pr2/ausnahmen/trycatch/BlossNicht.java | 2 +- .../ausnahmen/trycatch/ExceptionExample.java | 2 +- .../trycatch/FinallyMitSeiteneffekt.java | 2 +- .../pr2/ausnahmen/trycatch/GanzBoese.java | 2 +- .../java/pr2/ausnahmen/trycatch/Netzwerk.java | 2 +- .../ausnahmen/trycatch/TryCatchExample.java | 2 +- .../trycatch/TryCatchExampleZwei.java | 2 +- .../pr2/ausnahmen/trycatch/polymorphie/A.java | 2 +- .../pr2/ausnahmen/trycatch/polymorphie/B.java | 2 +- .../pr2/datenstrukturen/adt/BinaryTree.java | 14 ++ .../java/pr2/datenstrukturen/adt/Queue.java | 8 + .../datenstrukturen/adt/QueueException.java | 4 + .../java/pr2/datenstrukturen/adt/Stack.java | 8 + .../datenstrukturen/adt/StackException.java | 4 + .../pr2/datenstrukturen/adt/TreeNode.java | 22 +++ .../java/pr2/datenstrukturen/avl/AVLTree.java | 118 ++++++++++++ .../pr2/datenstrukturen/bt/BinaryTree.java | 66 +++++++ .../pr2/datenstrukturen/bt/SimpleTree.java | 94 ++++++++++ .../datenstrukturen/buffer/RingBuffer.java | 55 ++++++ .../java/pr2/datenstrukturen/graph/Graph.java | 54 ++++++ .../datenstrukturen/hash/BetterHashTable.java | 53 ++++++ .../pr2/datenstrukturen/hash/HashTable.java | 51 ++++++ .../datenstrukturen/hash/SimpleHashTable.java | 45 +++++ .../datenstrukturen/liste/ArrayIterator.java | 24 +++ .../liste/ArrayIteratorTest.java | 14 ++ .../liste/DoubleLinkedList.java | 112 ++++++++++++ .../pr2/datenstrukturen/liste/IntList.java | 9 + .../pr2/datenstrukturen/liste/LinkedList.java | 120 +++++++++++++ .../datenstrukturen/liste/Pr2LinkedList.java | 168 ++++++++++++++++++ .../liste/Pr2LinkedListTest.java | 124 +++++++++++++ .../pr2/datenstrukturen/liste/Pr2List.java | 61 +++++++ .../pr2/datenstrukturen/liste/Pr2Node.java | 23 +++ .../pr2/datenstrukturen/liste/TestLists.java | 31 ++++ .../java/pr2/datenstrukturen/queue/Queue.java | 42 +++++ .../datenstrukturen/search/BoyerMoore.java | 52 ++++++ .../java/pr2/datenstrukturen/search/KMP.java | 38 ++++ .../java/pr2/datenstrukturen/stack/Stack.java | 42 +++++ src/main/java/pr2/ds/avl/AVLTree.java | 2 +- src/main/java/pr2/ds/bt/BinaryTree.java | 2 +- src/main/java/pr2/ds/bt/SimpleTree.java | 2 +- src/main/java/pr2/ds/buffer/RingBuffer.java | 2 +- src/main/java/pr2/ds/graph/Graph.java | 2 +- .../java/pr2/ds/hash/BetterHashTable.java | 2 +- src/main/java/pr2/ds/hash/HashTable.java | 2 +- .../java/pr2/ds/hash/SimpleHashTable.java | 2 +- src/main/java/pr2/ds/liste/ArrayIterator.java | 2 +- .../java/pr2/ds/liste/ArrayIteratorTest.java | 2 +- .../java/pr2/ds/liste/DoubleLinkedList.java | 2 +- src/main/java/pr2/ds/liste/IntList.java | 2 +- src/main/java/pr2/ds/liste/LinkedList.java | 2 +- src/main/java/pr2/ds/liste/Pr2LinkedList.java | 2 +- .../java/pr2/ds/liste/Pr2LinkedListTest.java | 2 +- src/main/java/pr2/ds/liste/Pr2List.java | 2 +- src/main/java/pr2/ds/liste/Pr2Node.java | 2 +- src/main/java/pr2/ds/liste/TestLists.java | 2 +- src/main/java/pr2/ds/queue/Queue.java | 2 +- src/main/java/pr2/ds/search/BoyerMoore.java | 2 +- src/main/java/pr2/ds/search/KMP.java | 2 +- src/main/java/pr2/ds/stack/Stack.java | 2 +- .../records/newstyle/Rectangle.java | 26 +++ .../records/plain/Rectangle.java | 55 ++++++ src/main/java/pr2/exceptions/Java7.java | 118 ++++++++++++ .../pr2/exceptions/callstack/CallStack1.java | 40 +++++ .../pr2/exceptions/callstack/CallStack2.java | 29 +++ .../pr2/exceptions/callstack/CallStack3.java | 29 +++ .../exceptions/callstack/HandleOrDeclare.java | 53 ++++++ .../java/pr2/exceptions/eigene/Client.java | 26 +++ .../java/pr2/exceptions/eigene/Server.java | 21 +++ .../exceptions/eigene/ServerException.java | 24 +++ .../pr2/exceptions/eigene/SimpleExample2.java | 27 +++ .../pr2/exceptions/eigene/SimpleExamples.java | 25 +++ .../finall/TryCatchFinallyExample.java | 46 +++++ .../finall/TryCatchFinallyExample2.java | 51 ++++++ .../java/pr2/exceptions/junit/BrokenTest.java | 25 +++ .../pr2/exceptions/junit/TestMitExpected.java | 18 ++ .../pr2/exceptions/junit/TestMitTryCatch.java | 25 +++ .../java/pr2/exceptions/quiz/Finally.java | 21 +++ .../pr2/exceptions/trycatch/BlossNicht.java | 42 +++++ .../exceptions/trycatch/ExceptionExample.java | 16 ++ .../trycatch/FinallyMitSeiteneffekt.java | 23 +++ .../pr2/exceptions/trycatch/GanzBoese.java | 22 +++ .../pr2/exceptions/trycatch/Netzwerk.java | 36 ++++ .../exceptions/trycatch/TryCatchExample.java | 40 +++++ .../trycatch/TryCatchExampleZwei.java | 52 ++++++ .../exceptions/trycatch/polymorphie/A.java | 12 ++ .../exceptions/trycatch/polymorphie/B.java | 31 ++++ .../geschachtelte_klassen/MagicButton.java | 53 ++++++ .../anonym/v1/AnonymBeispiel.java | 17 ++ .../anonym/v1/Escape.java | 19 ++ .../anonym/v1/Outer.java | 9 + .../anonym/v2/Anonymous.java | 44 +++++ .../anonym/v2/Outer.java | 40 +++++ .../anonym/v2/Outer2.java | 33 ++++ .../anonym/v3/WasIstDennDas.java | 14 ++ .../basics/anonym/A.java | 9 + .../basics/anzahl/A.java | 8 + .../geschachtelte_klassen/basics/arten/A.java | 8 + .../geschachtelte_klassen/basics/local/A.java | 8 + .../geschachtelte_klassen/basics/priv/A.java | 11 ++ .../geschachtelte_klassen/basics/priv/C.java | 14 ++ .../basics/sichtbarkeit/A.java | 9 + .../geschachtelte_klassen/basics/tiefe/A.java | 10 ++ .../basics/vererbung/A.java | 12 ++ .../basics/vererbunginnen/A.java | 6 + .../callback/Berechnung.java | 12 ++ .../callback/Funktion.java | 8 + .../callback/TestBerechnung.java | 22 +++ .../geschachtelte_klassen/decompiled/A$B.java | 24 +++ .../geschachtelte_klassen/decompiled/A.java | 23 +++ .../geschachtelte_klassen/lambda/Aktion.java | 32 ++++ .../lambda/Berechnung.java | 13 ++ .../geschachtelte_klassen/lambda/Capture.java | 16 ++ .../lambda/ComparatorFactory.java | 20 +++ .../lambda/Funktion.java | 5 + .../geschachtelte_klassen/lambda/Rechner.java | 35 ++++ .../lambda/RechnerLambda.java | 14 ++ .../geschachtelte_klassen/lambda/Scoping.java | 17 ++ .../lambda/Scoping2.java | 20 +++ .../lambda/function/Rechner.java | 20 +++ .../lambda/function/RechnerKurz.java | 17 ++ .../lambda/methodref/Funktion.java | 9 + .../lambda/methodref/Funktionssammlung.java | 12 ++ .../lambda/methodref/Main.java | 8 + .../lambda/typing/Caller.java | 6 + .../lambda/typing/Runner.java | 6 + .../lambda/typing/TargetTyping.java | 22 +++ .../geschachtelte_klassen/local/Escape.java | 20 +++ .../local/LocalBeispiel.java | 17 ++ .../local/LocalMitVariable.java | 19 ++ .../local/LocalMitVariableUndInstanz.java | 21 +++ .../geschachtelte_klassen/local/Outer.java | 9 + .../nonstatic/computer/Computer.java | 17 ++ .../nonstatic/computer/Computer2.java | 16 ++ .../nonstatic/computer/Computer3.java | 16 ++ .../nonstatic/computer/Computer4.java | 34 ++++ .../nonstatic/computer/Outer.java | 6 + .../nonstatic/v1/Outer.java | 24 +++ .../nonstatic/v1/UseOuter.java | 15 ++ .../nonstatic/v2/Outer.java | 25 +++ .../nonstatic/v2/UseOuter.java | 12 ++ .../geschachtelte_klassen/nonstatic/v3/A.java | 27 +++ .../pr2/geschachtelte_klassen/quiz/Outer.java | 6 + .../geschachtelte_klassen/quiz/Twister.java | 25 +++ .../statisch/v1/Outer.java | 6 + .../statisch/v1/StaticMember.java | 25 +++ .../statisch/v2/Outer.java | 18 ++ .../statisch/v2/PrivaterZugriff.java | 25 +++ .../statisch/v2/UseOuter.java | 13 ++ .../statisch/v2/Zugriff.java | 29 +++ .../vererbung/Outer.java | 37 ++++ .../java/pr2/intro/junit/KomplexTest.java | 63 +++++++ .../java/pr2/intro/junit/KomplexeZahl.java | 87 +++++++++ .../pr2/intro/junit/KomplexeZahlTest.java | 38 ++++ .../java/pr2/nestedclasses/MagicButton.java | 2 +- .../anonym/v1/AnonymBeispiel.java | 2 +- .../pr2/nestedclasses/anonym/v1/Escape.java | 2 +- .../pr2/nestedclasses/anonym/v1/Outer.java | 2 +- .../nestedclasses/anonym/v2/Anonymous.java | 2 +- .../pr2/nestedclasses/anonym/v2/Outer.java | 2 +- .../pr2/nestedclasses/anonym/v2/Outer2.java | 2 +- .../anonym/v3/WasIstDennDas.java | 2 +- .../pr2/nestedclasses/basics/anonym/A.java | 2 +- .../pr2/nestedclasses/basics/anzahl/A.java | 2 +- .../pr2/nestedclasses/basics/arten/A.java | 2 +- .../pr2/nestedclasses/basics/local/A.java | 2 +- .../java/pr2/nestedclasses/basics/priv/A.java | 2 +- .../java/pr2/nestedclasses/basics/priv/C.java | 2 +- .../nestedclasses/basics/sichtbarkeit/A.java | 2 +- .../pr2/nestedclasses/basics/tiefe/A.java | 2 +- .../pr2/nestedclasses/basics/vererbung/A.java | 2 +- .../basics/vererbunginnen/A.java | 2 +- .../nestedclasses/callback/Berechnung.java | 2 +- .../pr2/nestedclasses/callback/Funktion.java | 2 +- .../callback/TestBerechnung.java | 2 +- .../pr2/nestedclasses/decompiled/A$B.java | 2 +- .../java/pr2/nestedclasses/decompiled/A.java | 2 +- .../java/pr2/nestedclasses/lambda/Aktion.java | 2 +- .../pr2/nestedclasses/lambda/Berechnung.java | 2 +- .../pr2/nestedclasses/lambda/Capture.java | 2 +- .../lambda/ComparatorFactory.java | 2 +- .../pr2/nestedclasses/lambda/Funktion.java | 2 +- .../pr2/nestedclasses/lambda/Rechner.java | 2 +- .../nestedclasses/lambda/RechnerLambda.java | 2 +- .../pr2/nestedclasses/lambda/Scoping.java | 2 +- .../pr2/nestedclasses/lambda/Scoping2.java | 2 +- .../lambda/function/Rechner.java | 2 +- .../lambda/function/RechnerKurz.java | 2 +- .../lambda/methodref/Funktion.java | 2 +- .../lambda/methodref/Funktionssammlung.java | 2 +- .../nestedclasses/lambda/methodref/Main.java | 2 +- .../nestedclasses/lambda/typing/Caller.java | 2 +- .../nestedclasses/lambda/typing/Runner.java | 2 +- .../lambda/typing/TargetTyping.java | 2 +- .../java/pr2/nestedclasses/local/Escape.java | 2 +- .../nestedclasses/local/LocalBeispiel.java | 2 +- .../nestedclasses/local/LocalMitVariable.java | 2 +- .../local/LocalMitVariableUndInstanz.java | 2 +- .../java/pr2/nestedclasses/local/Outer.java | 2 +- .../nonstatic/computer/Computer.java | 2 +- .../nonstatic/computer/Computer2.java | 2 +- .../nonstatic/computer/Computer3.java | 2 +- .../nonstatic/computer/Computer4.java | 2 +- .../nonstatic/computer/Outer.java | 2 +- .../pr2/nestedclasses/nonstatic/v1/Outer.java | 2 +- .../nestedclasses/nonstatic/v1/UseOuter.java | 2 +- .../pr2/nestedclasses/nonstatic/v2/Outer.java | 2 +- .../nestedclasses/nonstatic/v2/UseOuter.java | 2 +- .../pr2/nestedclasses/nonstatic/v3/A.java | 2 +- .../java/pr2/nestedclasses/quiz/Outer.java | 2 +- .../java/pr2/nestedclasses/quiz/Twister.java | 2 +- .../pr2/nestedclasses/statisch/v1/Outer.java | 2 +- .../statisch/v1/StaticMember.java | 2 +- .../pr2/nestedclasses/statisch/v2/Outer.java | 2 +- .../statisch/v2/PrivaterZugriff.java | 2 +- .../nestedclasses/statisch/v2/UseOuter.java | 2 +- .../nestedclasses/statisch/v2/Zugriff.java | 2 +- .../pr2/nestedclasses/vererbung/Outer.java | 2 +- src/main/java/pr2/oo/abstrakt/v1/Ente.java | 10 ++ src/main/java/pr2/oo/abstrakt/v1/Hund.java | 9 + src/main/java/pr2/oo/abstrakt/v1/Tier.java | 11 ++ .../java/pr2/oo/abstrakt/v1/Verwender.java | 15 ++ src/main/java/pr2/oo/abstrakt/v10/A.java | 13 ++ src/main/java/pr2/oo/abstrakt/v10/B.java | 15 ++ src/main/java/pr2/oo/abstrakt/v10/C.java | 9 + src/main/java/pr2/oo/abstrakt/v10/D.java | 4 + src/main/java/pr2/oo/abstrakt/v10/E.java | 9 + src/main/java/pr2/oo/abstrakt/v10/F.java | 4 + src/main/java/pr2/oo/abstrakt/v10/G.java | 13 ++ .../java/pr2/oo/abstrakt/v10/Verwender.java | 22 +++ src/main/java/pr2/oo/abstrakt/v11/A.java | 13 ++ src/main/java/pr2/oo/abstrakt/v11/B.java | 16 ++ src/main/java/pr2/oo/abstrakt/v11/C.java | 15 ++ src/main/java/pr2/oo/abstrakt/v11/D.java | 10 ++ src/main/java/pr2/oo/abstrakt/v2/Ente.java | 11 ++ src/main/java/pr2/oo/abstrakt/v2/Hund.java | 11 ++ src/main/java/pr2/oo/abstrakt/v2/Tier.java | 6 + .../java/pr2/oo/abstrakt/v2/Verwender.java | 23 +++ src/main/java/pr2/oo/abstrakt/v3/Ente.java | 10 ++ src/main/java/pr2/oo/abstrakt/v3/Hund.java | 13 ++ src/main/java/pr2/oo/abstrakt/v3/Tier.java | 10 ++ .../java/pr2/oo/abstrakt/v3/Verwender.java | 32 ++++ src/main/java/pr2/oo/abstrakt/v4/Ente.java | 13 ++ src/main/java/pr2/oo/abstrakt/v4/Hund.java | 13 ++ src/main/java/pr2/oo/abstrakt/v4/Tier.java | 11 ++ .../java/pr2/oo/abstrakt/v4/Verwender.java | 32 ++++ .../java/pr2/oo/abstrakt/v5/Angestellter.java | 13 ++ .../java/pr2/oo/abstrakt/v5/Arbeiter.java | 15 ++ .../pr2/oo/abstrakt/v5/Lohnbuchhaltung.java | 31 ++++ .../java/pr2/oo/abstrakt/v5/Mitarbeiter.java | 7 + .../java/pr2/oo/abstrakt/v5/Vorstand.java | 9 + .../java/pr2/oo/abstrakt/v6/Angestellter.java | 13 ++ .../java/pr2/oo/abstrakt/v6/Arbeiter.java | 15 ++ .../pr2/oo/abstrakt/v6/Lohnbuchhaltung.java | 15 ++ .../java/pr2/oo/abstrakt/v6/Mitarbeiter.java | 12 ++ .../java/pr2/oo/abstrakt/v6/Vorstand.java | 9 + .../java/pr2/oo/abstrakt/v7/Angestellter.java | 13 ++ .../java/pr2/oo/abstrakt/v7/Arbeiter.java | 15 ++ .../pr2/oo/abstrakt/v7/Lohnbuchhaltung.java | 15 ++ .../java/pr2/oo/abstrakt/v7/Mitarbeiter.java | 9 + .../java/pr2/oo/abstrakt/v7/Vorstand.java | 8 + .../java/pr2/oo/abstrakt/v8/Angestellter.java | 18 ++ src/main/java/pr2/oo/abstrakt/v8/Main.java | 14 ++ .../java/pr2/oo/abstrakt/v8/Mitarbeiter.java | 14 ++ .../java/pr2/oo/abstrakt/v8/Vorstand.java | 17 ++ .../java/pr2/oo/abstrakt/v9/Mitarbeiter.java | 23 +++ .../java/pr2/oo/finale/blankfinal/Kunde.java | 13 ++ .../pr2/oo/finale/v1/DeadCodeElemination.java | 18 ++ .../java/pr2/oo/finale/v1/Konstanten.java | 14 ++ .../oo/finale/v1/NoDeadCodeElemination.java | 18 ++ src/main/java/pr2/oo/finale/v2/A.java | 9 + src/main/java/pr2/oo/finale/v2/B.java | 14 ++ .../pr2/oo/finale/v2/FinaleVariablen.java | 37 ++++ .../java/pr2/oo/finale/v2/Konstanten.java | 8 + .../pr2/oo/finale/v2/Konstantenverwender.java | 15 ++ src/main/java/pr2/oo/finale/v3/A.java | 8 + src/main/java/pr2/oo/finale/v3/B.java | 8 + .../pr2/oo/interfaces/callback/Addition.java | 11 ++ .../oo/interfaces/callback/Berechnung.java | 20 +++ .../pr2/oo/interfaces/callback/Funktion.java | 8 + .../oo/interfaces/callback/Subtraktion.java | 11 ++ .../pr2/oo/interfaces/java8/ExtFlieger.java | 17 ++ .../java/pr2/oo/interfaces/java8/Flieger.java | 12 ++ .../pr2/oo/interfaces/java8/Flugzeug.java | 11 ++ src/main/java/pr2/oo/interfaces/java8/IA.java | 5 + src/main/java/pr2/oo/interfaces/java8/IB.java | 5 + .../java/pr2/oo/interfaces/java8/Impl.java | 5 + .../java/pr2/oo/interfaces/java8/Main.java | 11 ++ .../java/pr2/oo/interfaces/java8/Rechner.java | 10 ++ .../pr2/oo/interfaces/java8/diamond/A.java | 9 + .../pr2/oo/interfaces/java8/diamond/B.java | 10 ++ .../pr2/oo/interfaces/java8/diamond/C.java | 6 + .../pr2/oo/interfaces/java8/diamond/I1.java | 9 + .../pr2/oo/interfaces/java8/diamond/I2.java | 10 ++ .../pr2/oo/interfaces/java8/diamond/Main.java | 10 ++ .../oo/interfaces/mehrfachvererbung/A.java | 13 ++ .../oo/interfaces/mehrfachvererbung/I1.java | 8 + .../oo/interfaces/mehrfachvererbung/I2.java | 8 + .../java/pr2/oo/interfaces/v1/Flieger.java | 13 ++ .../java/pr2/oo/interfaces/v1/Flughafen.java | 13 ++ .../java/pr2/oo/interfaces/v1/Flugzeug.java | 19 ++ .../java/pr2/oo/interfaces/v2/Flieger.java | 15 ++ .../java/pr2/oo/interfaces/v2/Flieger2.java | 15 ++ .../java/pr2/oo/interfaces/v2/Flugzeug.java | 19 ++ .../java/pr2/oo/interfaces/v3/Airbus.java | 8 + src/main/java/pr2/oo/interfaces/v3/Ente.java | 22 +++ .../java/pr2/oo/interfaces/v3/Flieger.java | 10 ++ .../java/pr2/oo/interfaces/v3/Flugzeug.java | 19 ++ .../java/pr2/oo/interfaces/v3/Maschine.java | 8 + .../java/pr2/oo/interfaces/v3/Schwimmer.java | 9 + .../java/pr2/oo/interfaces/v3/Superman.java | 19 ++ src/main/java/pr2/oo/interfaces/v3/Tier.java | 9 + src/main/java/pr2/oo/interfaces/v3/Vogel.java | 8 + .../pr2/oo/interfaces/v3/Wasserflugzeug.java | 10 ++ .../java/pr2/oo/interfaces/v4/Konstanten.java | 8 + src/main/java/pr2/oo/interfaces/v4/Mathe.java | 11 ++ .../java/pr2/oo/interfaces/v4/Mathe2.java | 11 ++ .../java/pr2/oo/interfaces/v5/Sorter.java | 19 ++ .../pr2/oo/interfaces/v5/Telefonnummer.java | 40 +++++ src/main/java/pr2/oo/interfaces/v6/A.java | 8 + src/main/java/pr2/oo/interfaces/v6/B.java | 8 + src/main/java/pr2/oo/interfaces/v6/I1.java | 8 + src/main/java/pr2/oo/interfaces/v6/I2.java | 8 + src/main/java/pr2/oo/interfaces/v6/Main.java | 18 ++ .../java/pr2/oo/konstruktor/hierarchie/A.java | 14 ++ .../java/pr2/oo/konstruktor/hierarchie/B.java | 17 ++ .../java/pr2/oo/konstruktor/probleme/A.java | 17 ++ .../java/pr2/oo/konstruktor/probleme/B.java | 21 +++ .../java/pr2/oo/object/clone/CloneDemo.java | 16 ++ .../java/pr2/oo/object/clone/Mitarbeiter.java | 26 +++ src/main/java/pr2/oo/object/clone2/Main.java | 29 +++ src/main/java/pr2/oo/object/clone2/Schaf.java | 48 +++++ .../java/pr2/oo/object/equals/EqualsDemo.java | 21 +++ .../java/pr2/oo/object/equals/MeinDatum.java | 42 +++++ .../pr2/oo/object/equals/Mitarbeiter.java | 62 +++++++ .../java/pr2/oo/object/intern/InternDemo.java | 22 +++ src/main/java/pr2/oo/quiz/Ente.java | 20 +++ src/main/java/pr2/oo/quiz/Initializer.java | 21 +++ src/main/java/pr2/oo/quiz/QuizStatic.java | 16 ++ .../java/pr2/oo/quiz/binding/BindingQuiz.java | 31 ++++ .../java/pr2/oo/quiz/boxing/BoxingQuiz.java | 16 ++ .../oo/quiz/constructor/ConstructorQuiz.java | 19 ++ .../pr2/oo/quiz/constructor/NameHolder.java | 23 +++ src/main/java/pr2/oo/quiz/equals/A.java | 32 ++++ src/main/java/pr2/oo/quiz/equals2/A.java | 32 ++++ .../pr2/oo/quiz/polymorphie/Polymorphie.java | 29 +++ src/main/java/pr2/oo/quiz/verdecken/A.java | 14 ++ src/main/java/pr2/oo/quiz/verdecken/B.java | 19 ++ src/main/java/pr2/oo/quiz/vererbung/C.java | 19 ++ .../pr2/oo/statisch/apiimpl/Calculator.java | 9 + .../statisch/apiimpl/CalculatorFactory.java | 13 ++ .../oo/statisch/apiimpl/CalculatorImpl.java | 15 ++ .../CalculatorImplQuantumSuperDuper.java | 22 +++ .../pr2/oo/statisch/apiimpl/Verwender.java | 14 ++ src/main/java/pr2/oo/statisch/cycle/A.java | 16 ++ src/main/java/pr2/oo/statisch/cycle/B.java | 16 ++ src/main/java/pr2/oo/statisch/cycle/C.java | 10 ++ .../pr2/oo/statisch/factory/Erzeugter.java | 13 ++ .../java/pr2/oo/statisch/factory/Factory.java | 11 ++ .../pr2/oo/statisch/initializer/Crash.java | 13 ++ .../oo/statisch/initializer/CrashUser.java | 9 + .../pr2/oo/statisch/singleton/Broken.java | 25 +++ .../java/pr2/oo/statisch/singleton/Firma.java | 17 ++ .../pr2/oo/statisch/singleton/Firma2.java | 21 +++ src/main/java/pr2/oo/statisch/v1/Ticket.java | 18 ++ .../java/pr2/oo/statisch/v2/TestTicket.java | 15 ++ src/main/java/pr2/oo/statisch/v2/Ticket.java | 22 +++ .../java/pr2/oo/statisch/v3/TestTicket.java | 14 ++ src/main/java/pr2/oo/statisch/v3/Ticket.java | 30 ++++ src/main/java/pr2/oo/statisch/v4/A.java | 11 ++ src/main/java/pr2/oo/statisch/v4/B.java | 11 ++ src/main/java/pr2/oo/statisch/v4/Test.java | 17 ++ src/main/java/pr2/oo/ueberschreiben/A.java | 19 ++ .../pr2/oo/ueberschreiben/rueckgabetyp/A.java | 11 ++ .../pr2/oo/ueberschreiben/rueckgabetyp/B.java | 11 ++ src/main/java/pr2/oo/verdecken/A.java | 20 +++ src/main/java/pr2/oo/verdecken/B.java | 13 ++ src/main/java/pr2/oo/verdecken/C.java | 8 + src/main/java/pr2/oo/verdecken/D.java | 8 + src/main/java/pr2/oo/verdecken/E.java | 12 ++ .../pr2/oo/verdecken/ellipse/EllipseDemo.java | 23 +++ .../oo/verdecken/ellipse/EllipseDetails.java | 17 ++ .../verdecken/ellipse/EllipseDetailsEcht.java | 17 ++ .../ueberladen/UeberladenUndPolymorphie.java | 29 +++ .../pr2/oo/vererbung/privat/Kampfechse.java | 9 + .../pr2/oo/vererbung/privat/Rennechse.java | 23 +++ .../pr2/oo/vererbung/privat/Terrarium.java | 21 +++ .../oo/vererbung/v1/Geschaeftsfuehrer.java | 8 + .../vererbung/v1/GeschaeftsfuehrerBean.java | 36 ++++ .../java/pr2/oo/vererbung/v1/Manager.java | 8 + .../java/pr2/oo/vererbung/v1/Mitarbeiter.java | 17 ++ .../pr2/oo/vererbung/v1/MitarbeiterBean.java | 34 ++++ .../oo/vererbung/v2/Geschaeftsfuehrer.java | 8 + .../java/pr2/oo/vererbung/v2/Manager.java | 18 ++ .../java/pr2/oo/vererbung/v2/Mitarbeiter.java | 17 ++ .../oo/vererbung/v3/Geschaeftsfuehrer.java | 15 ++ .../java/pr2/oo/vererbung/v3/Manager.java | 14 ++ .../java/pr2/oo/vererbung/v3/Mitarbeiter.java | 17 ++ .../oo/vererbung/v4/Geschaeftsfuehrer.java | 13 ++ .../java/pr2/oo/vererbung/v4/Manager.java | 13 ++ .../pr2/oo/vererbung/v4/Methodenaufruf.java | 144 +++++++++++++++ .../java/pr2/oo/vererbung/v4/Mitarbeiter.java | 17 ++ src/main/java/pr2/oo/vererbung/v5/Klasse.java | 8 + .../java/pr2/oo/vererbung/v5/Klasse2.java | 14 ++ .../java/pr2/oo/vererbung/v5/Manager.java | 20 +++ .../java/pr2/oo/vererbung/v5/Mitarbeiter.java | 35 ++++ .../wasprotectedwirklichheisst/pack1/A.java | 12 ++ .../wasprotectedwirklichheisst/pack2/B.java | 17 ++ .../java/pr2/oo/wrapper/AutoboxingDemo.java | 21 +++ .../java/pr2/oo/wrapper/BoxingFailure.java | 21 +++ src/main/java/pr2/oo/wrapper/WrapperDemo.java | 16 ++ .../pr2/oo1/konstruktor/hierarchie/A.java | 2 +- .../pr2/oo1/konstruktor/hierarchie/B.java | 2 +- .../java/pr2/oo1/konstruktor/probleme/A.java | 2 +- .../java/pr2/oo1/konstruktor/probleme/B.java | 2 +- .../java/pr2/oo1/object/clone/CloneDemo.java | 2 +- .../pr2/oo1/object/clone/Mitarbeiter.java | 2 +- src/main/java/pr2/oo1/object/clone2/Main.java | 2 +- .../java/pr2/oo1/object/clone2/Schaf.java | 2 +- .../pr2/oo1/object/equals/EqualsDemo.java | 2 +- .../java/pr2/oo1/object/equals/MeinDatum.java | 2 +- .../pr2/oo1/object/equals/Mitarbeiter.java | 2 +- .../pr2/oo1/object/intern/InternDemo.java | 2 +- .../pr2/oo1/quiz/binding/BindingQuiz.java | 2 +- .../java/pr2/oo1/quiz/boxing/BoxingQuiz.java | 2 +- .../oo1/quiz/constructor/ConstructorQuiz.java | 2 +- .../pr2/oo1/quiz/constructor/NameHolder.java | 2 +- src/main/java/pr2/oo1/quiz/equals/A.java | 2 +- src/main/java/pr2/oo1/quiz/equals2/A.java | 2 +- .../pr2/oo1/quiz/polymorphie/Polymorphie.java | 2 +- src/main/java/pr2/oo1/quiz/verdecken/A.java | 2 +- src/main/java/pr2/oo1/quiz/verdecken/B.java | 2 +- src/main/java/pr2/oo1/quiz/vererbung/C.java | 2 +- src/main/java/pr2/oo1/ueberschreiben/A.java | 2 +- .../oo1/ueberschreiben/rueckgabetyp/A.java | 2 +- .../oo1/ueberschreiben/rueckgabetyp/B.java | 2 +- src/main/java/pr2/oo1/verdecken/A.java | 2 +- src/main/java/pr2/oo1/verdecken/B.java | 2 +- src/main/java/pr2/oo1/verdecken/C.java | 2 +- src/main/java/pr2/oo1/verdecken/D.java | 2 +- src/main/java/pr2/oo1/verdecken/E.java | 2 +- .../oo1/verdecken/ellipse/EllipseDemo.java | 2 +- .../oo1/verdecken/ellipse/EllipseDetails.java | 2 +- .../verdecken/ellipse/EllipseDetailsEcht.java | 2 +- .../ueberladen/UeberladenUndPolymorphie.java | 2 +- .../pr2/oo1/vererbung/privat/Kampfechse.java | 2 +- .../pr2/oo1/vererbung/privat/Rennechse.java | 2 +- .../pr2/oo1/vererbung/privat/Terrarium.java | 2 +- .../oo1/vererbung/v1/Geschaeftsfuehrer.java | 2 +- .../vererbung/v1/GeschaeftsfuehrerBean.java | 2 +- .../java/pr2/oo1/vererbung/v1/Manager.java | 2 +- .../pr2/oo1/vererbung/v1/Mitarbeiter.java | 2 +- .../pr2/oo1/vererbung/v1/MitarbeiterBean.java | 2 +- .../oo1/vererbung/v2/Geschaeftsfuehrer.java | 2 +- .../java/pr2/oo1/vererbung/v2/Manager.java | 2 +- .../pr2/oo1/vererbung/v2/Mitarbeiter.java | 2 +- .../oo1/vererbung/v3/Geschaeftsfuehrer.java | 2 +- .../java/pr2/oo1/vererbung/v3/Manager.java | 2 +- .../pr2/oo1/vererbung/v3/Mitarbeiter.java | 2 +- .../oo1/vererbung/v4/Geschaeftsfuehrer.java | 2 +- .../java/pr2/oo1/vererbung/v4/Manager.java | 2 +- .../pr2/oo1/vererbung/v4/Methodenaufruf.java | 2 +- .../pr2/oo1/vererbung/v4/Mitarbeiter.java | 2 +- .../java/pr2/oo1/vererbung/v5/Klasse.java | 2 +- .../java/pr2/oo1/vererbung/v5/Klasse2.java | 2 +- .../java/pr2/oo1/vererbung/v5/Manager.java | 2 +- .../pr2/oo1/vererbung/v5/Mitarbeiter.java | 2 +- .../wasprotectedwirklichheisst/pack1/A.java | 2 +- .../wasprotectedwirklichheisst/pack2/B.java | 4 +- .../java/pr2/oo2/interfaces/v4/Mathe2.java | 2 - 532 files changed, 7648 insertions(+), 199 deletions(-) create mode 100644 README.md create mode 100644 src/main/java/pr2/algorithmen/searching/BinarySearch.java create mode 100644 src/main/java/pr2/algorithmen/searching/LinearSearch.java create mode 100644 src/main/java/pr2/algorithmen/searching/Searcher.java create mode 100644 src/main/java/pr2/algorithmen/searching/TestSearch.java create mode 100644 src/main/java/pr2/algorithmen/shuffle/FisherYatesShuffle.java create mode 100644 src/main/java/pr2/algorithmen/shuffle/NaiveShuffle.java create mode 100644 src/main/java/pr2/algorithmen/shuffle/Shuffler.java create mode 100644 src/main/java/pr2/algorithmen/shuffle/TestShuffle.java create mode 100644 src/main/java/pr2/algorithmen/sorting/BubbleSort.java create mode 100644 src/main/java/pr2/algorithmen/sorting/InsertionSort.java create mode 100644 src/main/java/pr2/algorithmen/sorting/MergeSort.java create mode 100644 src/main/java/pr2/algorithmen/sorting/QuickSort.java create mode 100644 src/main/java/pr2/algorithmen/sorting/SelectionSort.java create mode 100644 src/main/java/pr2/algorithmen/sorting/Sorter.java create mode 100644 src/main/java/pr2/algorithmen/sorting/TestSorting.java create mode 100644 src/main/java/pr2/algorithmen/textsearch/BoyerMooreTextSearch.java create mode 100644 src/main/java/pr2/algorithmen/textsearch/BruteForceTextSearch.java create mode 100644 src/main/java/pr2/algorithmen/textsearch/KMPTextSearch.java create mode 100644 src/main/java/pr2/algorithmen/textsearch/TestTextSearch.java create mode 100644 src/main/java/pr2/algorithmen/textsearch/TextSearch.java create mode 100644 src/main/java/pr2/datenstrukturen/adt/BinaryTree.java create mode 100644 src/main/java/pr2/datenstrukturen/adt/Queue.java create mode 100644 src/main/java/pr2/datenstrukturen/adt/QueueException.java create mode 100644 src/main/java/pr2/datenstrukturen/adt/Stack.java create mode 100644 src/main/java/pr2/datenstrukturen/adt/StackException.java create mode 100644 src/main/java/pr2/datenstrukturen/adt/TreeNode.java create mode 100644 src/main/java/pr2/datenstrukturen/avl/AVLTree.java create mode 100644 src/main/java/pr2/datenstrukturen/bt/BinaryTree.java create mode 100644 src/main/java/pr2/datenstrukturen/bt/SimpleTree.java create mode 100644 src/main/java/pr2/datenstrukturen/buffer/RingBuffer.java create mode 100644 src/main/java/pr2/datenstrukturen/graph/Graph.java create mode 100644 src/main/java/pr2/datenstrukturen/hash/BetterHashTable.java create mode 100644 src/main/java/pr2/datenstrukturen/hash/HashTable.java create mode 100644 src/main/java/pr2/datenstrukturen/hash/SimpleHashTable.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/ArrayIterator.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/ArrayIteratorTest.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/DoubleLinkedList.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/IntList.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/LinkedList.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/Pr2LinkedList.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/Pr2LinkedListTest.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/Pr2List.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/Pr2Node.java create mode 100644 src/main/java/pr2/datenstrukturen/liste/TestLists.java create mode 100644 src/main/java/pr2/datenstrukturen/queue/Queue.java create mode 100644 src/main/java/pr2/datenstrukturen/search/BoyerMoore.java create mode 100644 src/main/java/pr2/datenstrukturen/search/KMP.java create mode 100644 src/main/java/pr2/datenstrukturen/stack/Stack.java create mode 100644 src/main/java/pr2/enumerationen/records/newstyle/Rectangle.java create mode 100644 src/main/java/pr2/enumerationen/records/plain/Rectangle.java create mode 100644 src/main/java/pr2/exceptions/Java7.java create mode 100644 src/main/java/pr2/exceptions/callstack/CallStack1.java create mode 100644 src/main/java/pr2/exceptions/callstack/CallStack2.java create mode 100644 src/main/java/pr2/exceptions/callstack/CallStack3.java create mode 100644 src/main/java/pr2/exceptions/callstack/HandleOrDeclare.java create mode 100644 src/main/java/pr2/exceptions/eigene/Client.java create mode 100644 src/main/java/pr2/exceptions/eigene/Server.java create mode 100644 src/main/java/pr2/exceptions/eigene/ServerException.java create mode 100644 src/main/java/pr2/exceptions/eigene/SimpleExample2.java create mode 100644 src/main/java/pr2/exceptions/eigene/SimpleExamples.java create mode 100644 src/main/java/pr2/exceptions/finall/TryCatchFinallyExample.java create mode 100644 src/main/java/pr2/exceptions/finall/TryCatchFinallyExample2.java create mode 100644 src/main/java/pr2/exceptions/junit/BrokenTest.java create mode 100644 src/main/java/pr2/exceptions/junit/TestMitExpected.java create mode 100644 src/main/java/pr2/exceptions/junit/TestMitTryCatch.java create mode 100644 src/main/java/pr2/exceptions/quiz/Finally.java create mode 100644 src/main/java/pr2/exceptions/trycatch/BlossNicht.java create mode 100644 src/main/java/pr2/exceptions/trycatch/ExceptionExample.java create mode 100644 src/main/java/pr2/exceptions/trycatch/FinallyMitSeiteneffekt.java create mode 100644 src/main/java/pr2/exceptions/trycatch/GanzBoese.java create mode 100644 src/main/java/pr2/exceptions/trycatch/Netzwerk.java create mode 100644 src/main/java/pr2/exceptions/trycatch/TryCatchExample.java create mode 100644 src/main/java/pr2/exceptions/trycatch/TryCatchExampleZwei.java create mode 100644 src/main/java/pr2/exceptions/trycatch/polymorphie/A.java create mode 100644 src/main/java/pr2/exceptions/trycatch/polymorphie/B.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/MagicButton.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/anonym/v1/AnonymBeispiel.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/anonym/v1/Escape.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/anonym/v1/Outer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/anonym/v2/Anonymous.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/anonym/v2/Outer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/anonym/v2/Outer2.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/anonym/v3/WasIstDennDas.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/anonym/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/anzahl/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/arten/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/local/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/priv/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/priv/C.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/sichtbarkeit/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/tiefe/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/vererbung/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/basics/vererbunginnen/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/callback/Berechnung.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/callback/Funktion.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/callback/TestBerechnung.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/decompiled/A$B.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/decompiled/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/Aktion.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/Berechnung.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/Capture.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/ComparatorFactory.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/Funktion.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/Rechner.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/RechnerLambda.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/Scoping.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/Scoping2.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/function/Rechner.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/function/RechnerKurz.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Funktion.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Funktionssammlung.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Main.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/typing/Caller.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/typing/Runner.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/lambda/typing/TargetTyping.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/local/Escape.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/local/LocalBeispiel.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/local/LocalMitVariable.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/local/LocalMitVariableUndInstanz.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/local/Outer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer2.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer3.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer4.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Outer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/v1/Outer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/v1/UseOuter.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/v2/Outer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/v2/UseOuter.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/nonstatic/v3/A.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/quiz/Outer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/quiz/Twister.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/statisch/v1/Outer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/statisch/v1/StaticMember.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/statisch/v2/Outer.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/statisch/v2/PrivaterZugriff.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/statisch/v2/UseOuter.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/statisch/v2/Zugriff.java create mode 100644 src/main/java/pr2/geschachtelte_klassen/vererbung/Outer.java create mode 100644 src/main/java/pr2/intro/junit/KomplexTest.java create mode 100644 src/main/java/pr2/intro/junit/KomplexeZahl.java create mode 100644 src/main/java/pr2/intro/junit/KomplexeZahlTest.java create mode 100644 src/main/java/pr2/oo/abstrakt/v1/Ente.java create mode 100644 src/main/java/pr2/oo/abstrakt/v1/Hund.java create mode 100644 src/main/java/pr2/oo/abstrakt/v1/Tier.java create mode 100644 src/main/java/pr2/oo/abstrakt/v1/Verwender.java create mode 100644 src/main/java/pr2/oo/abstrakt/v10/A.java create mode 100644 src/main/java/pr2/oo/abstrakt/v10/B.java create mode 100644 src/main/java/pr2/oo/abstrakt/v10/C.java create mode 100644 src/main/java/pr2/oo/abstrakt/v10/D.java create mode 100644 src/main/java/pr2/oo/abstrakt/v10/E.java create mode 100644 src/main/java/pr2/oo/abstrakt/v10/F.java create mode 100644 src/main/java/pr2/oo/abstrakt/v10/G.java create mode 100644 src/main/java/pr2/oo/abstrakt/v10/Verwender.java create mode 100644 src/main/java/pr2/oo/abstrakt/v11/A.java create mode 100644 src/main/java/pr2/oo/abstrakt/v11/B.java create mode 100644 src/main/java/pr2/oo/abstrakt/v11/C.java create mode 100644 src/main/java/pr2/oo/abstrakt/v11/D.java create mode 100644 src/main/java/pr2/oo/abstrakt/v2/Ente.java create mode 100644 src/main/java/pr2/oo/abstrakt/v2/Hund.java create mode 100644 src/main/java/pr2/oo/abstrakt/v2/Tier.java create mode 100644 src/main/java/pr2/oo/abstrakt/v2/Verwender.java create mode 100644 src/main/java/pr2/oo/abstrakt/v3/Ente.java create mode 100644 src/main/java/pr2/oo/abstrakt/v3/Hund.java create mode 100644 src/main/java/pr2/oo/abstrakt/v3/Tier.java create mode 100644 src/main/java/pr2/oo/abstrakt/v3/Verwender.java create mode 100644 src/main/java/pr2/oo/abstrakt/v4/Ente.java create mode 100644 src/main/java/pr2/oo/abstrakt/v4/Hund.java create mode 100644 src/main/java/pr2/oo/abstrakt/v4/Tier.java create mode 100644 src/main/java/pr2/oo/abstrakt/v4/Verwender.java create mode 100644 src/main/java/pr2/oo/abstrakt/v5/Angestellter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v5/Arbeiter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v5/Lohnbuchhaltung.java create mode 100644 src/main/java/pr2/oo/abstrakt/v5/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v5/Vorstand.java create mode 100644 src/main/java/pr2/oo/abstrakt/v6/Angestellter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v6/Arbeiter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v6/Lohnbuchhaltung.java create mode 100644 src/main/java/pr2/oo/abstrakt/v6/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v6/Vorstand.java create mode 100644 src/main/java/pr2/oo/abstrakt/v7/Angestellter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v7/Arbeiter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v7/Lohnbuchhaltung.java create mode 100644 src/main/java/pr2/oo/abstrakt/v7/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v7/Vorstand.java create mode 100644 src/main/java/pr2/oo/abstrakt/v8/Angestellter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v8/Main.java create mode 100644 src/main/java/pr2/oo/abstrakt/v8/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/abstrakt/v8/Vorstand.java create mode 100644 src/main/java/pr2/oo/abstrakt/v9/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/finale/blankfinal/Kunde.java create mode 100644 src/main/java/pr2/oo/finale/v1/DeadCodeElemination.java create mode 100644 src/main/java/pr2/oo/finale/v1/Konstanten.java create mode 100644 src/main/java/pr2/oo/finale/v1/NoDeadCodeElemination.java create mode 100644 src/main/java/pr2/oo/finale/v2/A.java create mode 100644 src/main/java/pr2/oo/finale/v2/B.java create mode 100644 src/main/java/pr2/oo/finale/v2/FinaleVariablen.java create mode 100644 src/main/java/pr2/oo/finale/v2/Konstanten.java create mode 100644 src/main/java/pr2/oo/finale/v2/Konstantenverwender.java create mode 100644 src/main/java/pr2/oo/finale/v3/A.java create mode 100644 src/main/java/pr2/oo/finale/v3/B.java create mode 100644 src/main/java/pr2/oo/interfaces/callback/Addition.java create mode 100644 src/main/java/pr2/oo/interfaces/callback/Berechnung.java create mode 100644 src/main/java/pr2/oo/interfaces/callback/Funktion.java create mode 100644 src/main/java/pr2/oo/interfaces/callback/Subtraktion.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/ExtFlieger.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/Flieger.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/Flugzeug.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/IA.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/IB.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/Impl.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/Main.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/Rechner.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/diamond/A.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/diamond/B.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/diamond/C.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/diamond/I1.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/diamond/I2.java create mode 100644 src/main/java/pr2/oo/interfaces/java8/diamond/Main.java create mode 100644 src/main/java/pr2/oo/interfaces/mehrfachvererbung/A.java create mode 100644 src/main/java/pr2/oo/interfaces/mehrfachvererbung/I1.java create mode 100644 src/main/java/pr2/oo/interfaces/mehrfachvererbung/I2.java create mode 100644 src/main/java/pr2/oo/interfaces/v1/Flieger.java create mode 100644 src/main/java/pr2/oo/interfaces/v1/Flughafen.java create mode 100644 src/main/java/pr2/oo/interfaces/v1/Flugzeug.java create mode 100644 src/main/java/pr2/oo/interfaces/v2/Flieger.java create mode 100644 src/main/java/pr2/oo/interfaces/v2/Flieger2.java create mode 100644 src/main/java/pr2/oo/interfaces/v2/Flugzeug.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Airbus.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Ente.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Flieger.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Flugzeug.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Maschine.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Schwimmer.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Superman.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Tier.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Vogel.java create mode 100644 src/main/java/pr2/oo/interfaces/v3/Wasserflugzeug.java create mode 100644 src/main/java/pr2/oo/interfaces/v4/Konstanten.java create mode 100644 src/main/java/pr2/oo/interfaces/v4/Mathe.java create mode 100644 src/main/java/pr2/oo/interfaces/v4/Mathe2.java create mode 100644 src/main/java/pr2/oo/interfaces/v5/Sorter.java create mode 100644 src/main/java/pr2/oo/interfaces/v5/Telefonnummer.java create mode 100644 src/main/java/pr2/oo/interfaces/v6/A.java create mode 100644 src/main/java/pr2/oo/interfaces/v6/B.java create mode 100644 src/main/java/pr2/oo/interfaces/v6/I1.java create mode 100644 src/main/java/pr2/oo/interfaces/v6/I2.java create mode 100644 src/main/java/pr2/oo/interfaces/v6/Main.java create mode 100644 src/main/java/pr2/oo/konstruktor/hierarchie/A.java create mode 100644 src/main/java/pr2/oo/konstruktor/hierarchie/B.java create mode 100644 src/main/java/pr2/oo/konstruktor/probleme/A.java create mode 100644 src/main/java/pr2/oo/konstruktor/probleme/B.java create mode 100644 src/main/java/pr2/oo/object/clone/CloneDemo.java create mode 100644 src/main/java/pr2/oo/object/clone/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/object/clone2/Main.java create mode 100644 src/main/java/pr2/oo/object/clone2/Schaf.java create mode 100644 src/main/java/pr2/oo/object/equals/EqualsDemo.java create mode 100644 src/main/java/pr2/oo/object/equals/MeinDatum.java create mode 100644 src/main/java/pr2/oo/object/equals/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/object/intern/InternDemo.java create mode 100644 src/main/java/pr2/oo/quiz/Ente.java create mode 100644 src/main/java/pr2/oo/quiz/Initializer.java create mode 100644 src/main/java/pr2/oo/quiz/QuizStatic.java create mode 100644 src/main/java/pr2/oo/quiz/binding/BindingQuiz.java create mode 100644 src/main/java/pr2/oo/quiz/boxing/BoxingQuiz.java create mode 100644 src/main/java/pr2/oo/quiz/constructor/ConstructorQuiz.java create mode 100644 src/main/java/pr2/oo/quiz/constructor/NameHolder.java create mode 100644 src/main/java/pr2/oo/quiz/equals/A.java create mode 100644 src/main/java/pr2/oo/quiz/equals2/A.java create mode 100644 src/main/java/pr2/oo/quiz/polymorphie/Polymorphie.java create mode 100644 src/main/java/pr2/oo/quiz/verdecken/A.java create mode 100644 src/main/java/pr2/oo/quiz/verdecken/B.java create mode 100644 src/main/java/pr2/oo/quiz/vererbung/C.java create mode 100644 src/main/java/pr2/oo/statisch/apiimpl/Calculator.java create mode 100644 src/main/java/pr2/oo/statisch/apiimpl/CalculatorFactory.java create mode 100644 src/main/java/pr2/oo/statisch/apiimpl/CalculatorImpl.java create mode 100644 src/main/java/pr2/oo/statisch/apiimpl/CalculatorImplQuantumSuperDuper.java create mode 100644 src/main/java/pr2/oo/statisch/apiimpl/Verwender.java create mode 100644 src/main/java/pr2/oo/statisch/cycle/A.java create mode 100644 src/main/java/pr2/oo/statisch/cycle/B.java create mode 100644 src/main/java/pr2/oo/statisch/cycle/C.java create mode 100644 src/main/java/pr2/oo/statisch/factory/Erzeugter.java create mode 100644 src/main/java/pr2/oo/statisch/factory/Factory.java create mode 100644 src/main/java/pr2/oo/statisch/initializer/Crash.java create mode 100644 src/main/java/pr2/oo/statisch/initializer/CrashUser.java create mode 100644 src/main/java/pr2/oo/statisch/singleton/Broken.java create mode 100644 src/main/java/pr2/oo/statisch/singleton/Firma.java create mode 100644 src/main/java/pr2/oo/statisch/singleton/Firma2.java create mode 100644 src/main/java/pr2/oo/statisch/v1/Ticket.java create mode 100644 src/main/java/pr2/oo/statisch/v2/TestTicket.java create mode 100644 src/main/java/pr2/oo/statisch/v2/Ticket.java create mode 100644 src/main/java/pr2/oo/statisch/v3/TestTicket.java create mode 100644 src/main/java/pr2/oo/statisch/v3/Ticket.java create mode 100644 src/main/java/pr2/oo/statisch/v4/A.java create mode 100644 src/main/java/pr2/oo/statisch/v4/B.java create mode 100644 src/main/java/pr2/oo/statisch/v4/Test.java create mode 100644 src/main/java/pr2/oo/ueberschreiben/A.java create mode 100644 src/main/java/pr2/oo/ueberschreiben/rueckgabetyp/A.java create mode 100644 src/main/java/pr2/oo/ueberschreiben/rueckgabetyp/B.java create mode 100644 src/main/java/pr2/oo/verdecken/A.java create mode 100644 src/main/java/pr2/oo/verdecken/B.java create mode 100644 src/main/java/pr2/oo/verdecken/C.java create mode 100644 src/main/java/pr2/oo/verdecken/D.java create mode 100644 src/main/java/pr2/oo/verdecken/E.java create mode 100644 src/main/java/pr2/oo/verdecken/ellipse/EllipseDemo.java create mode 100644 src/main/java/pr2/oo/verdecken/ellipse/EllipseDetails.java create mode 100644 src/main/java/pr2/oo/verdecken/ellipse/EllipseDetailsEcht.java create mode 100644 src/main/java/pr2/oo/verdecken/ueberladen/UeberladenUndPolymorphie.java create mode 100644 src/main/java/pr2/oo/vererbung/privat/Kampfechse.java create mode 100644 src/main/java/pr2/oo/vererbung/privat/Rennechse.java create mode 100644 src/main/java/pr2/oo/vererbung/privat/Terrarium.java create mode 100644 src/main/java/pr2/oo/vererbung/v1/Geschaeftsfuehrer.java create mode 100644 src/main/java/pr2/oo/vererbung/v1/GeschaeftsfuehrerBean.java create mode 100644 src/main/java/pr2/oo/vererbung/v1/Manager.java create mode 100644 src/main/java/pr2/oo/vererbung/v1/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/vererbung/v1/MitarbeiterBean.java create mode 100644 src/main/java/pr2/oo/vererbung/v2/Geschaeftsfuehrer.java create mode 100644 src/main/java/pr2/oo/vererbung/v2/Manager.java create mode 100644 src/main/java/pr2/oo/vererbung/v2/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/vererbung/v3/Geschaeftsfuehrer.java create mode 100644 src/main/java/pr2/oo/vererbung/v3/Manager.java create mode 100644 src/main/java/pr2/oo/vererbung/v3/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/vererbung/v4/Geschaeftsfuehrer.java create mode 100644 src/main/java/pr2/oo/vererbung/v4/Manager.java create mode 100644 src/main/java/pr2/oo/vererbung/v4/Methodenaufruf.java create mode 100644 src/main/java/pr2/oo/vererbung/v4/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/vererbung/v5/Klasse.java create mode 100644 src/main/java/pr2/oo/vererbung/v5/Klasse2.java create mode 100644 src/main/java/pr2/oo/vererbung/v5/Manager.java create mode 100644 src/main/java/pr2/oo/vererbung/v5/Mitarbeiter.java create mode 100644 src/main/java/pr2/oo/vererbung/wasprotectedwirklichheisst/pack1/A.java create mode 100644 src/main/java/pr2/oo/vererbung/wasprotectedwirklichheisst/pack2/B.java create mode 100644 src/main/java/pr2/oo/wrapper/AutoboxingDemo.java create mode 100644 src/main/java/pr2/oo/wrapper/BoxingFailure.java create mode 100644 src/main/java/pr2/oo/wrapper/WrapperDemo.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..6005d06 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Beispiele zur Vorlesung PR2 + +Hier finden Sie die Beispiele aus den Folien (und dem Skript) zur Vorlesung PR2. + + * [01_auffrischung](src/main/java/pr2/auffrischung) + * [02_intro](src/main/java/pr2/intro) + * [03_strukturierung](src/main/java/pr2/strukturierung) + * [04_oo](src/main/java/pr2/oo) + * [05_algorithmen](src/main/java/pr2/algorithmen) + * [07_exceptions](src/main/java/pr2/exceptions) + * [08_enumerationen](src/main/java/pr2/enumerationen) + * [09_generics](src/main/java/pr2/generics) + * [10_geschachtelte_klassen](src/main/java/pr2/geschachtelte_klassen) + * [11_datenstrukturen](src/main/java/pr2/datenstrukturen) + * [12_collections](src/main/java/pr2/collections) + * [13_streams](src/main/java/pr2/streams) + * [14_threads](src/main/java/pr2/threads) + * [15_io](src/main/java/pr2/io) + * [16_reflection](src/main/java/pr2/reflection) diff --git a/src/main/java/pr2/ads/adt/BinaryTree.java b/src/main/java/pr2/ads/adt/BinaryTree.java index 92c1a03..87d0401 100644 --- a/src/main/java/pr2/ads/adt/BinaryTree.java +++ b/src/main/java/pr2/ads/adt/BinaryTree.java @@ -1,4 +1,4 @@ -package pr2.ads.adt; +package pr2.algorithmen.adt; public class BinaryTree { private TreeNode head; diff --git a/src/main/java/pr2/ads/adt/Queue.java b/src/main/java/pr2/ads/adt/Queue.java index bac42cf..b75ebe1 100644 --- a/src/main/java/pr2/ads/adt/Queue.java +++ b/src/main/java/pr2/ads/adt/Queue.java @@ -1,4 +1,4 @@ -package pr2.ads.adt; +package pr2.algorithmen.adt; public interface Queue { public void enter(Object obj) throws QueueException; diff --git a/src/main/java/pr2/ads/adt/QueueException.java b/src/main/java/pr2/ads/adt/QueueException.java index 1f71b03..bbf6d07 100644 --- a/src/main/java/pr2/ads/adt/QueueException.java +++ b/src/main/java/pr2/ads/adt/QueueException.java @@ -1,4 +1,4 @@ -package pr2.ads.adt; +package pr2.algorithmen.adt; public class QueueException extends RuntimeException { } diff --git a/src/main/java/pr2/ads/adt/Stack.java b/src/main/java/pr2/ads/adt/Stack.java index 5aff585..b347fc0 100644 --- a/src/main/java/pr2/ads/adt/Stack.java +++ b/src/main/java/pr2/ads/adt/Stack.java @@ -1,4 +1,4 @@ -package pr2.ads.adt; +package pr2.algorithmen.adt; public interface Stack { void push(Object obj) throws StackException; diff --git a/src/main/java/pr2/ads/adt/StackException.java b/src/main/java/pr2/ads/adt/StackException.java index cd8aac0..6269c3b 100644 --- a/src/main/java/pr2/ads/adt/StackException.java +++ b/src/main/java/pr2/ads/adt/StackException.java @@ -1,4 +1,4 @@ -package pr2.ads.adt; +package pr2.algorithmen.adt; public class StackException extends RuntimeException { } diff --git a/src/main/java/pr2/ads/adt/TreeNode.java b/src/main/java/pr2/ads/adt/TreeNode.java index 5ab3529..3f55fae 100644 --- a/src/main/java/pr2/ads/adt/TreeNode.java +++ b/src/main/java/pr2/ads/adt/TreeNode.java @@ -1,4 +1,4 @@ -package pr2.ads.adt; +package pr2.algorithmen.adt; public class TreeNode { TreeNode left = null; diff --git a/src/main/java/pr2/ads/searching/BinarySearch.java b/src/main/java/pr2/ads/searching/BinarySearch.java index 08e087e..3092e07 100644 --- a/src/main/java/pr2/ads/searching/BinarySearch.java +++ b/src/main/java/pr2/ads/searching/BinarySearch.java @@ -1,4 +1,4 @@ -package pr2.ads.searching; +package pr2.algorithmen.searching; public class BinarySearch implements Searcher { @Override diff --git a/src/main/java/pr2/ads/searching/LinearSearch.java b/src/main/java/pr2/ads/searching/LinearSearch.java index 5861284..a33f0b1 100644 --- a/src/main/java/pr2/ads/searching/LinearSearch.java +++ b/src/main/java/pr2/ads/searching/LinearSearch.java @@ -1,4 +1,4 @@ -package pr2.ads.searching; +package pr2.algorithmen.searching; public class LinearSearch implements Searcher { @Override diff --git a/src/main/java/pr2/ads/searching/Searcher.java b/src/main/java/pr2/ads/searching/Searcher.java index fe89094..161dc8e 100644 --- a/src/main/java/pr2/ads/searching/Searcher.java +++ b/src/main/java/pr2/ads/searching/Searcher.java @@ -1,4 +1,4 @@ -package pr2.ads.searching; +package pr2.algorithmen.searching; public interface Searcher { diff --git a/src/main/java/pr2/ads/searching/TestSearch.java b/src/main/java/pr2/ads/searching/TestSearch.java index 43e6089..34d04f9 100644 --- a/src/main/java/pr2/ads/searching/TestSearch.java +++ b/src/main/java/pr2/ads/searching/TestSearch.java @@ -1,4 +1,4 @@ -package pr2.ads.searching; +package pr2.algorithmen.searching; import java.util.Random; diff --git a/src/main/java/pr2/ads/shuffle/FisherYatesShuffle.java b/src/main/java/pr2/ads/shuffle/FisherYatesShuffle.java index f785166..efa33a2 100644 --- a/src/main/java/pr2/ads/shuffle/FisherYatesShuffle.java +++ b/src/main/java/pr2/ads/shuffle/FisherYatesShuffle.java @@ -1,4 +1,4 @@ -package pr2.ads.shuffle; +package pr2.algorithmen.shuffle; import java.util.Random; diff --git a/src/main/java/pr2/ads/shuffle/NaiveShuffle.java b/src/main/java/pr2/ads/shuffle/NaiveShuffle.java index 591b6d4..10d2225 100644 --- a/src/main/java/pr2/ads/shuffle/NaiveShuffle.java +++ b/src/main/java/pr2/ads/shuffle/NaiveShuffle.java @@ -1,4 +1,4 @@ -package pr2.ads.shuffle; +package pr2.algorithmen.shuffle; import java.util.LinkedList; import java.util.Random; diff --git a/src/main/java/pr2/ads/shuffle/Shuffler.java b/src/main/java/pr2/ads/shuffle/Shuffler.java index 0b2c5ea..c14e15a 100644 --- a/src/main/java/pr2/ads/shuffle/Shuffler.java +++ b/src/main/java/pr2/ads/shuffle/Shuffler.java @@ -1,4 +1,4 @@ -package pr2.ads.shuffle; +package pr2.algorithmen.shuffle; public interface Shuffler { diff --git a/src/main/java/pr2/ads/shuffle/TestShuffle.java b/src/main/java/pr2/ads/shuffle/TestShuffle.java index b7f0dc8..f8bcd51 100644 --- a/src/main/java/pr2/ads/shuffle/TestShuffle.java +++ b/src/main/java/pr2/ads/shuffle/TestShuffle.java @@ -1,4 +1,4 @@ -package pr2.ads.shuffle; +package pr2.algorithmen.shuffle; import java.util.Arrays; diff --git a/src/main/java/pr2/ads/sorting/BubbleSort.java b/src/main/java/pr2/ads/sorting/BubbleSort.java index b186e33..a70030b 100644 --- a/src/main/java/pr2/ads/sorting/BubbleSort.java +++ b/src/main/java/pr2/ads/sorting/BubbleSort.java @@ -1,4 +1,4 @@ -package pr2.ads.sorting; +package pr2.algorithmen.sorting; public class BubbleSort implements Sorter { diff --git a/src/main/java/pr2/ads/sorting/InsertionSort.java b/src/main/java/pr2/ads/sorting/InsertionSort.java index 15bda5d..cf154c1 100644 --- a/src/main/java/pr2/ads/sorting/InsertionSort.java +++ b/src/main/java/pr2/ads/sorting/InsertionSort.java @@ -1,4 +1,4 @@ -package pr2.ads.sorting; +package pr2.algorithmen.sorting; public class InsertionSort implements Sorter { diff --git a/src/main/java/pr2/ads/sorting/MergeSort.java b/src/main/java/pr2/ads/sorting/MergeSort.java index 03831d8..097e955 100644 --- a/src/main/java/pr2/ads/sorting/MergeSort.java +++ b/src/main/java/pr2/ads/sorting/MergeSort.java @@ -1,4 +1,4 @@ -package pr2.ads.sorting; +package pr2.algorithmen.sorting; public class MergeSort implements Sorter { diff --git a/src/main/java/pr2/ads/sorting/QuickSort.java b/src/main/java/pr2/ads/sorting/QuickSort.java index 1aef27b..f93eb57 100644 --- a/src/main/java/pr2/ads/sorting/QuickSort.java +++ b/src/main/java/pr2/ads/sorting/QuickSort.java @@ -1,4 +1,4 @@ -package pr2.ads.sorting; +package pr2.algorithmen.sorting; public class QuickSort implements Sorter { diff --git a/src/main/java/pr2/ads/sorting/SelectionSort.java b/src/main/java/pr2/ads/sorting/SelectionSort.java index bc88421..af96c68 100644 --- a/src/main/java/pr2/ads/sorting/SelectionSort.java +++ b/src/main/java/pr2/ads/sorting/SelectionSort.java @@ -1,4 +1,4 @@ -package pr2.ads.sorting; +package pr2.algorithmen.sorting; public class SelectionSort implements Sorter { diff --git a/src/main/java/pr2/ads/sorting/Sorter.java b/src/main/java/pr2/ads/sorting/Sorter.java index 0721117..a57a8a2 100644 --- a/src/main/java/pr2/ads/sorting/Sorter.java +++ b/src/main/java/pr2/ads/sorting/Sorter.java @@ -1,4 +1,4 @@ -package pr2.ads.sorting; +package pr2.algorithmen.sorting; public interface Sorter { diff --git a/src/main/java/pr2/ads/sorting/TestSorting.java b/src/main/java/pr2/ads/sorting/TestSorting.java index 6b96310..6c8a4af 100644 --- a/src/main/java/pr2/ads/sorting/TestSorting.java +++ b/src/main/java/pr2/ads/sorting/TestSorting.java @@ -1,6 +1,6 @@ -package pr2.ads.sorting; +package pr2.algorithmen.sorting; -import pr2.nestedclasses.lambda.function.RechnerKurz; +import pr2.geschachtelte_klassen.lambda.function.RechnerKurz; import java.util.*; diff --git a/src/main/java/pr2/ads/textsearch/BoyerMooreTextSearch.java b/src/main/java/pr2/ads/textsearch/BoyerMooreTextSearch.java index fa8cb7b..8b7cb00 100644 --- a/src/main/java/pr2/ads/textsearch/BoyerMooreTextSearch.java +++ b/src/main/java/pr2/ads/textsearch/BoyerMooreTextSearch.java @@ -1,4 +1,4 @@ -package pr2.ads.textsearch; +package pr2.algorithmen.textsearch; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/pr2/ads/textsearch/BruteForceTextSearch.java b/src/main/java/pr2/ads/textsearch/BruteForceTextSearch.java index 3f37ca9..7e676fb 100644 --- a/src/main/java/pr2/ads/textsearch/BruteForceTextSearch.java +++ b/src/main/java/pr2/ads/textsearch/BruteForceTextSearch.java @@ -1,4 +1,4 @@ -package pr2.ads.textsearch; +package pr2.algorithmen.textsearch; public class BruteForceTextSearch implements TextSearch { diff --git a/src/main/java/pr2/ads/textsearch/KMPTextSearch.java b/src/main/java/pr2/ads/textsearch/KMPTextSearch.java index d47ba77..2798cfe 100644 --- a/src/main/java/pr2/ads/textsearch/KMPTextSearch.java +++ b/src/main/java/pr2/ads/textsearch/KMPTextSearch.java @@ -1,4 +1,4 @@ -package pr2.ads.textsearch; +package pr2.algorithmen.textsearch; public class KMPTextSearch implements TextSearch { diff --git a/src/main/java/pr2/ads/textsearch/TestTextSearch.java b/src/main/java/pr2/ads/textsearch/TestTextSearch.java index 8f14ee5..144e831 100644 --- a/src/main/java/pr2/ads/textsearch/TestTextSearch.java +++ b/src/main/java/pr2/ads/textsearch/TestTextSearch.java @@ -1,4 +1,4 @@ -package pr2.ads.textsearch; +package pr2.algorithmen.textsearch; public class TestTextSearch { public static void main(String[] args) { diff --git a/src/main/java/pr2/ads/textsearch/TextSearch.java b/src/main/java/pr2/ads/textsearch/TextSearch.java index 46bc87b..fd1b76b 100644 --- a/src/main/java/pr2/ads/textsearch/TextSearch.java +++ b/src/main/java/pr2/ads/textsearch/TextSearch.java @@ -1,4 +1,4 @@ -package pr2.ads.textsearch; +package pr2.algorithmen.textsearch; public interface TextSearch { diff --git a/src/main/java/pr2/algorithmen/searching/BinarySearch.java b/src/main/java/pr2/algorithmen/searching/BinarySearch.java new file mode 100644 index 0000000..3092e07 --- /dev/null +++ b/src/main/java/pr2/algorithmen/searching/BinarySearch.java @@ -0,0 +1,23 @@ +package pr2.algorithmen.searching; + +public class BinarySearch implements Searcher { + @Override + public int search(int e, int[] data) { + int u = 0; + int o = data.length - 1; + while (u <= o) { + int m = (u + o) / 2; + if (data[m] == e) { + return m; + } + else if (data[m] > e) { + o = m - 1; + } + else { + u = m + 1; + } + } + + return NOT_FOUND; + } +} diff --git a/src/main/java/pr2/algorithmen/searching/LinearSearch.java b/src/main/java/pr2/algorithmen/searching/LinearSearch.java new file mode 100644 index 0000000..a33f0b1 --- /dev/null +++ b/src/main/java/pr2/algorithmen/searching/LinearSearch.java @@ -0,0 +1,14 @@ +package pr2.algorithmen.searching; + +public class LinearSearch implements Searcher { + @Override + public int search(int e, int[] data) { + for (int i = 0; i < data.length; i++) { + if (e == data[i]) { + return i; + } + } + + return NOT_FOUND; + } +} diff --git a/src/main/java/pr2/algorithmen/searching/Searcher.java b/src/main/java/pr2/algorithmen/searching/Searcher.java new file mode 100644 index 0000000..161dc8e --- /dev/null +++ b/src/main/java/pr2/algorithmen/searching/Searcher.java @@ -0,0 +1,8 @@ +package pr2.algorithmen.searching; + +public interface Searcher { + + int NOT_FOUND = -1; + + int search(int e, int[] data); +} diff --git a/src/main/java/pr2/algorithmen/searching/TestSearch.java b/src/main/java/pr2/algorithmen/searching/TestSearch.java new file mode 100644 index 0000000..34d04f9 --- /dev/null +++ b/src/main/java/pr2/algorithmen/searching/TestSearch.java @@ -0,0 +1,27 @@ +package pr2.algorithmen.searching; + +import java.util.Random; + +public class TestSearch { + + public static void main(String[] args) { + final int size = 1000; + var data = new int[size]; + var r = new Random(); + + for (int i = 0; i < data.length; i++) { + data[i] = i; + } + + Searcher s; + int index; + + s = new LinearSearch(); + index = s.search(r.nextInt(size), data); + System.out.println(index); + + s = new BinarySearch(); + index = s.search(r.nextInt(size), data); + System.out.println(index); + } +} diff --git a/src/main/java/pr2/algorithmen/shuffle/FisherYatesShuffle.java b/src/main/java/pr2/algorithmen/shuffle/FisherYatesShuffle.java new file mode 100644 index 0000000..efa33a2 --- /dev/null +++ b/src/main/java/pr2/algorithmen/shuffle/FisherYatesShuffle.java @@ -0,0 +1,18 @@ +package pr2.algorithmen.shuffle; + +import java.util.Random; + +public class FisherYatesShuffle implements Shuffler { + + @Override + public void shuffle(int[] data) { + Random rand = new Random(); + + for (int i = data.length - 1; i > 0; i--) { + int randomIndexToSwap = rand.nextInt(data.length); + int temp = data[randomIndexToSwap]; + data[randomIndexToSwap] = data[i]; + data[i] = temp; + } + } +} diff --git a/src/main/java/pr2/algorithmen/shuffle/NaiveShuffle.java b/src/main/java/pr2/algorithmen/shuffle/NaiveShuffle.java new file mode 100644 index 0000000..10d2225 --- /dev/null +++ b/src/main/java/pr2/algorithmen/shuffle/NaiveShuffle.java @@ -0,0 +1,28 @@ +package pr2.algorithmen.shuffle; + +import java.util.LinkedList; +import java.util.Random; + +public class NaiveShuffle implements Shuffler { + @Override + public void shuffle(int[] data) { + Random rand = new Random(); + + int n = data.length; + + var result = new int[n]; + var index = new LinkedList(); + + for (int i = 0; i < n; i++) { + index.add(i); + } + + for (int i = 0; i < n; i++) { + int z = rand.nextInt(n - i); + result[i] = data[index.get(z)]; + index.remove(z); + } + + System.arraycopy(result, 0, data, 0, n); + } +} diff --git a/src/main/java/pr2/algorithmen/shuffle/Shuffler.java b/src/main/java/pr2/algorithmen/shuffle/Shuffler.java new file mode 100644 index 0000000..c14e15a --- /dev/null +++ b/src/main/java/pr2/algorithmen/shuffle/Shuffler.java @@ -0,0 +1,12 @@ +package pr2.algorithmen.shuffle; + +public interface Shuffler { + + void shuffle(int[] data); + + default void fill(int[] data) { + for (int i = 0; i < data.length; i++) { + data[i] = i; + } + } +} diff --git a/src/main/java/pr2/algorithmen/shuffle/TestShuffle.java b/src/main/java/pr2/algorithmen/shuffle/TestShuffle.java new file mode 100644 index 0000000..f8bcd51 --- /dev/null +++ b/src/main/java/pr2/algorithmen/shuffle/TestShuffle.java @@ -0,0 +1,20 @@ +package pr2.algorithmen.shuffle; + +import java.util.Arrays; + +public class TestShuffle { + + public static void main(String[] args) { + Shuffler naive = new NaiveShuffle(); + Shuffler fisher = new FisherYatesShuffle(); + + int[] data = new int[10]; + naive.fill(data); + naive.shuffle(data); + System.out.println(Arrays.toString(data)); + + fisher.fill(data); + fisher.shuffle(data); + System.out.println(Arrays.toString(data)); + } +} diff --git a/src/main/java/pr2/algorithmen/sorting/BubbleSort.java b/src/main/java/pr2/algorithmen/sorting/BubbleSort.java new file mode 100644 index 0000000..a70030b --- /dev/null +++ b/src/main/java/pr2/algorithmen/sorting/BubbleSort.java @@ -0,0 +1,24 @@ +package pr2.algorithmen.sorting; + +public class BubbleSort implements Sorter { + + @Override + public void sort(int[] data) { + boolean swapped; + do { + swapped = false; + for (int i = 0; i < data.length - 1; i++) { + if (data[i] > data[i + 1]) { + // Elemente vertauschen + swap(data, i, i + 1); + swapped = true; + } + } + } while (swapped); + } + + @Override + public String toString() { + return "BubbleSort"; + } +} diff --git a/src/main/java/pr2/algorithmen/sorting/InsertionSort.java b/src/main/java/pr2/algorithmen/sorting/InsertionSort.java new file mode 100644 index 0000000..cf154c1 --- /dev/null +++ b/src/main/java/pr2/algorithmen/sorting/InsertionSort.java @@ -0,0 +1,28 @@ +package pr2.algorithmen.sorting; + +public class InsertionSort implements Sorter { + + @Override + public void sort(int[] data) { + for (int i = 1; i < data.length; i++) { + int m = data[i]; + int j = i; + while (j > 0) { + if (data[j - 1] >= m) { + /* Verschiebe data[j - 1] eine Position nach rechts */ + data[j] = data[j - 1]; + j--; + } + else { + break; + } + } + data[j] = m; + } + } + + @Override + public String toString() { + return "InsertionSort"; + } +} diff --git a/src/main/java/pr2/algorithmen/sorting/MergeSort.java b/src/main/java/pr2/algorithmen/sorting/MergeSort.java new file mode 100644 index 0000000..097e955 --- /dev/null +++ b/src/main/java/pr2/algorithmen/sorting/MergeSort.java @@ -0,0 +1,46 @@ +package pr2.algorithmen.sorting; + +public class MergeSort implements Sorter { + + void msort(int[] array, int le, int ri, int[] helper) { + int i, j, k; + if (ri > le) { + // zu sortierendes Feld teilen + int mid = (ri + le) / 2; + + // Teilfelder sortieren + msort(array, le, mid, helper); + msort(array, mid + 1, ri, helper); + + // Hilfsfeld aufbauen + for (k = le; k <= mid; k++) { + helper[k] = array[k]; + } + + for (k = mid; k < ri; k++) { + helper[ri + mid - k] = array[k + 1]; + } + + // Ergebnisse mischen über Hilfsfeld + i = le; j = ri; + for (k = le; k <= ri; k++) { + if (helper[i] < helper[j]) { + array[k] = helper[i++]; + } else { + array[k] = helper[j--]; + } + } + } + } + + @Override + public void sort(int[] data) { + int[] helper = new int[data.length]; + msort(data, 0, data.length - 1, helper); + } + + @Override + public String toString() { + return "MergeSort"; + } +} diff --git a/src/main/java/pr2/algorithmen/sorting/QuickSort.java b/src/main/java/pr2/algorithmen/sorting/QuickSort.java new file mode 100644 index 0000000..f93eb57 --- /dev/null +++ b/src/main/java/pr2/algorithmen/sorting/QuickSort.java @@ -0,0 +1,47 @@ +package pr2.algorithmen.sorting; + +public class QuickSort implements Sorter { + + int partition(int[] array, int u, int o, int p) { + int pn = u; + int pv = array[p]; + // Pivot-Element an das Ende verschieben + swap(array, p, o); + for (int i = u; i < o; i++) { + if (array[i] <= pv) { + swap(array, pn++, i); + } + } + + // Pivot-Element an die richtige Position kopieren + swap(array, o, pn); + + // neue Pivot-Position zurückgeben + return pn; + } + + + // Hilfsmethode zum rekursiven Sortieren + void qsort(int[] array, int u, int o) { + + // Pivot-Element bestimmen + int p = (u + o) / 2; + if (o > u) { + // Feld zerlegen + int pn = partition(array, u, o, p); + // und Partitionen sortieren + qsort(array, u, pn - 1); + qsort(array, pn + 1, o); + } + } + + @Override + public void sort(int[] data) { + qsort(data, 0, data.length - 1); + } + + @Override + public String toString() { + return "QuickSort"; + } +} diff --git a/src/main/java/pr2/algorithmen/sorting/SelectionSort.java b/src/main/java/pr2/algorithmen/sorting/SelectionSort.java new file mode 100644 index 0000000..af96c68 --- /dev/null +++ b/src/main/java/pr2/algorithmen/sorting/SelectionSort.java @@ -0,0 +1,26 @@ +package pr2.algorithmen.sorting; + +public class SelectionSort implements Sorter { + + @Override + public void sort(int[] data) { + int marker = data.length - 1; + while (marker >= 0) { + // bestimme größtes Element + int max = 0; + for (int i = 1; i <= marker; i++) { + if (data[i] > data[max]) { + max = i; + } + } + // tausche array[marker] mit diesem Element + swap(data, marker, max); + marker--; + } + } + + @Override + public String toString() { + return "SelectionSort"; + } +} diff --git a/src/main/java/pr2/algorithmen/sorting/Sorter.java b/src/main/java/pr2/algorithmen/sorting/Sorter.java new file mode 100644 index 0000000..a57a8a2 --- /dev/null +++ b/src/main/java/pr2/algorithmen/sorting/Sorter.java @@ -0,0 +1,12 @@ +package pr2.algorithmen.sorting; + +public interface Sorter { + + void sort(int[] data); + + default void swap(int[] data, int i1, int i2) { + int tmp = data[i1]; + data[i1] = data[i2]; + data[i2] = tmp; + } +} diff --git a/src/main/java/pr2/algorithmen/sorting/TestSorting.java b/src/main/java/pr2/algorithmen/sorting/TestSorting.java new file mode 100644 index 0000000..bbfffe8 --- /dev/null +++ b/src/main/java/pr2/algorithmen/sorting/TestSorting.java @@ -0,0 +1,73 @@ +package pr2.algorithmen.sorting; + +import java.util.*; + +public class TestSorting { + + private static void shuffle(int[] data) { + Random rand = new Random(); + + for (int i = 0; i < data.length; i++) { + int randomIndexToSwap = rand.nextInt(data.length); + int temp = data[randomIndexToSwap]; + data[randomIndexToSwap] = data[i]; + data[i] = temp; + } + } + + static long testAlgorithm(Class clazz, int size, int runs) { + + Sorter s; + + var data = new int[size]; + for (int i = 0; i < data.length; i++) { + data[i] = i; + } + + long start = System.nanoTime(); + + try { + s = (Sorter) clazz.getDeclaredConstructor().newInstance(); + + for (int i = 0; i < runs; i++) { + shuffle(data); + s.sort(data); + } + } + catch (Exception e) { + // do nothing + return 0; + } + + + long runtime = System.nanoTime() - start; + + return runtime; + + } + + public static void measure(int size_steps, int max_size, int runs) { + System.out.println("Runs\tBS\tIS\tMS\tQS\tSS"); + for (int size = 0; size <= max_size; size += size_steps) { + long bs = testAlgorithm(BubbleSort.class, size, runs); + long is = testAlgorithm(InsertionSort.class, size, runs); + long ms = testAlgorithm(MergeSort.class, size, runs); + long qs = testAlgorithm(QuickSort.class, size, runs); + long ss = testAlgorithm(SelectionSort.class, size, runs); + System.out.printf("%d\t%d\t%d\t%d\t%d\t%d\n", size, bs, is, ms, qs, ss); + } + } + public static void main(String[] args) { + + measure(10, 1000, 100); + + final int size = 1000; + final int runs = 1000; + + testAlgorithm(BubbleSort.class, size, runs); + testAlgorithm(InsertionSort.class, size, runs); + testAlgorithm(MergeSort.class, size, runs); + testAlgorithm(QuickSort.class, size, runs); + testAlgorithm(SelectionSort.class, size, runs); + } +} diff --git a/src/main/java/pr2/algorithmen/textsearch/BoyerMooreTextSearch.java b/src/main/java/pr2/algorithmen/textsearch/BoyerMooreTextSearch.java new file mode 100644 index 0000000..8b7cb00 --- /dev/null +++ b/src/main/java/pr2/algorithmen/textsearch/BoyerMooreTextSearch.java @@ -0,0 +1,49 @@ +package pr2.algorithmen.textsearch; + +import java.util.HashMap; +import java.util.Map; + +public class BoyerMooreTextSearch implements TextSearch { + + public int search(String haystack, String needle) { + char[] text = haystack.toCharArray(); + char[] pattern = needle.toCharArray(); + + int n = text.length; + int m = pattern.length; + // Test for empty string + if (m == 0) return 0; + // Initialization, create Map of last position of each character = O(n) + Map last = new HashMap<>(); + for (char c : text) { + // set all chars, by default, to -1 + last.put(c, -1); + } + for (int i = 0; i < m; i++) { + // update last seen positions + last.put(pattern[i], i); + } + //Start with the end of the pattern aligned at index m-1 in the text. + //index into the text + int i = m - 1; + // index into the pattern + int k = m - 1; + while (i < n) { + if (text[i] == pattern[k]) { + // match! return i if complete match; otherwise, keep checking + if (k == 0) { + return i; + } + i--; k--; + } + else { // jump step + restart at end of pattern + //iterate over text + i += m - Math.min(k, 1 + last.get(text[i])); + //move to end of pattern + k = m - 1; + } + } + // not found + return NOT_FOUND; + } +} diff --git a/src/main/java/pr2/algorithmen/textsearch/BruteForceTextSearch.java b/src/main/java/pr2/algorithmen/textsearch/BruteForceTextSearch.java new file mode 100644 index 0000000..7e676fb --- /dev/null +++ b/src/main/java/pr2/algorithmen/textsearch/BruteForceTextSearch.java @@ -0,0 +1,22 @@ +package pr2.algorithmen.textsearch; + +public class BruteForceTextSearch implements TextSearch { + + public int search(String haystack, String needle) { + int n = haystack.length(); + int m = needle.length(); + + for (int i = 0; i <= n - m; i++) { + int j; + for (j = 0; j < m; j++) { + if (haystack.charAt(i + j) != needle.charAt(j)) { + break; + } + } + if (j == m) { + return i; + } + } + return NOT_FOUND; + } +} diff --git a/src/main/java/pr2/algorithmen/textsearch/KMPTextSearch.java b/src/main/java/pr2/algorithmen/textsearch/KMPTextSearch.java new file mode 100644 index 0000000..2798cfe --- /dev/null +++ b/src/main/java/pr2/algorithmen/textsearch/KMPTextSearch.java @@ -0,0 +1,46 @@ +package pr2.algorithmen.textsearch; + +public class KMPTextSearch implements TextSearch { + + public int search(String haystack, String needle) { + int[] lps = computeLPS(needle); + int i = 0, j = 0; + while (i < haystack.length()) { + if (needle.charAt(j) == haystack.charAt(i)) { + i++; + j++; + } + if (j == needle.length()) { + return i - j; + } else if (i < haystack.length() && needle.charAt(j) != haystack.charAt(i)) { + if (j != 0) { + j = lps[j - 1]; + } else { + i = i + 1; + } + } + } + return -1; + } + + public int[] computeLPS(String pattern) { + int[] lps = new int[pattern.length()]; + int j = 0; + for (int i = 1; i < pattern.length();) { + if (pattern.charAt(i) == pattern.charAt(j)) { + lps[i] = j + 1; + i++; + j++; + } else { + if (j != 0) { + j = lps[j - 1]; + } else { + lps[i] = 0; + i++; + } + } + } + return lps; + } + +} diff --git a/src/main/java/pr2/algorithmen/textsearch/TestTextSearch.java b/src/main/java/pr2/algorithmen/textsearch/TestTextSearch.java new file mode 100644 index 0000000..144e831 --- /dev/null +++ b/src/main/java/pr2/algorithmen/textsearch/TestTextSearch.java @@ -0,0 +1,21 @@ +package pr2.algorithmen.textsearch; + +public class TestTextSearch { + public static void main(String[] args) { + + String haystack = "DASISTEINSINNLOSERTEXT"; + String needle = "SINN"; + + TextSearch bf = new BruteForceTextSearch(); + System.out.println(bf.search(haystack, needle)); + + TextSearch kmp = new KMPTextSearch(); + System.out.println(kmp.search(haystack, needle)); + + TextSearch bm = new BoyerMooreTextSearch(); + System.out.println(bm.search(haystack, needle)); + + + + } +} diff --git a/src/main/java/pr2/algorithmen/textsearch/TextSearch.java b/src/main/java/pr2/algorithmen/textsearch/TextSearch.java new file mode 100644 index 0000000..fd1b76b --- /dev/null +++ b/src/main/java/pr2/algorithmen/textsearch/TextSearch.java @@ -0,0 +1,8 @@ +package pr2.algorithmen.textsearch; + +public interface TextSearch { + + int NOT_FOUND = -1; + + int search(String haystack, String needle); +} diff --git a/src/main/java/pr2/ausnahmen/Java7.java b/src/main/java/pr2/ausnahmen/Java7.java index effd05d..c7565b7 100644 --- a/src/main/java/pr2/ausnahmen/Java7.java +++ b/src/main/java/pr2/ausnahmen/Java7.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.ausnahmen; +package pr2.exceptions; import java.io.FileInputStream; import java.io.FileNotFoundException; diff --git a/src/main/java/pr2/ausnahmen/callstack/CallStack1.java b/src/main/java/pr2/ausnahmen/callstack/CallStack1.java index 1da74c6..6ab6c54 100644 --- a/src/main/java/pr2/ausnahmen/callstack/CallStack1.java +++ b/src/main/java/pr2/ausnahmen/callstack/CallStack1.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.callstack; +package pr2.exceptions.callstack; import java.io.FileInputStream; import java.io.IOException; diff --git a/src/main/java/pr2/ausnahmen/callstack/CallStack2.java b/src/main/java/pr2/ausnahmen/callstack/CallStack2.java index 980ccc3..6815ceb 100644 --- a/src/main/java/pr2/ausnahmen/callstack/CallStack2.java +++ b/src/main/java/pr2/ausnahmen/callstack/CallStack2.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.callstack; +package pr2.exceptions.callstack; import java.io.FileInputStream; import java.io.IOException; diff --git a/src/main/java/pr2/ausnahmen/callstack/CallStack3.java b/src/main/java/pr2/ausnahmen/callstack/CallStack3.java index 73981f3..7d618cc 100644 --- a/src/main/java/pr2/ausnahmen/callstack/CallStack3.java +++ b/src/main/java/pr2/ausnahmen/callstack/CallStack3.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.callstack; +package pr2.exceptions.callstack; import java.io.FileInputStream; import java.io.IOException; diff --git a/src/main/java/pr2/ausnahmen/callstack/HandleOrDeclare.java b/src/main/java/pr2/ausnahmen/callstack/HandleOrDeclare.java index ef9888f..3bff015 100644 --- a/src/main/java/pr2/ausnahmen/callstack/HandleOrDeclare.java +++ b/src/main/java/pr2/ausnahmen/callstack/HandleOrDeclare.java @@ -1,5 +1,5 @@ -package pr2.ausnahmen.callstack; +package pr2.exceptions.callstack; import java.io.FileNotFoundException; import java.io.IOException; diff --git a/src/main/java/pr2/ausnahmen/eigene/Client.java b/src/main/java/pr2/ausnahmen/eigene/Client.java index 03fa669..7846140 100644 --- a/src/main/java/pr2/ausnahmen/eigene/Client.java +++ b/src/main/java/pr2/ausnahmen/eigene/Client.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.eigene; +package pr2.exceptions.eigene; public class Client { diff --git a/src/main/java/pr2/ausnahmen/eigene/Server.java b/src/main/java/pr2/ausnahmen/eigene/Server.java index 715e646..3a41a5d 100644 --- a/src/main/java/pr2/ausnahmen/eigene/Server.java +++ b/src/main/java/pr2/ausnahmen/eigene/Server.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.eigene; +package pr2.exceptions.eigene; public class Server { diff --git a/src/main/java/pr2/ausnahmen/eigene/ServerException.java b/src/main/java/pr2/ausnahmen/eigene/ServerException.java index 6ef6ecb..b5b0d35 100644 --- a/src/main/java/pr2/ausnahmen/eigene/ServerException.java +++ b/src/main/java/pr2/ausnahmen/eigene/ServerException.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.eigene; +package pr2.exceptions.eigene; public class ServerException extends Exception { diff --git a/src/main/java/pr2/ausnahmen/eigene/SimpleExample2.java b/src/main/java/pr2/ausnahmen/eigene/SimpleExample2.java index 0e9435e..2a098a0 100644 --- a/src/main/java/pr2/ausnahmen/eigene/SimpleExample2.java +++ b/src/main/java/pr2/ausnahmen/eigene/SimpleExample2.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.ausnahmen.eigene; +package pr2.exceptions.eigene; import java.io.IOException; diff --git a/src/main/java/pr2/ausnahmen/eigene/SimpleExamples.java b/src/main/java/pr2/ausnahmen/eigene/SimpleExamples.java index 07a7f36..28319c2 100644 --- a/src/main/java/pr2/ausnahmen/eigene/SimpleExamples.java +++ b/src/main/java/pr2/ausnahmen/eigene/SimpleExamples.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.ausnahmen.eigene; +package pr2.exceptions.eigene; import java.io.IOException; diff --git a/src/main/java/pr2/ausnahmen/finall/TryCatchFinallyExample.java b/src/main/java/pr2/ausnahmen/finall/TryCatchFinallyExample.java index c957faf..1d3e041 100644 --- a/src/main/java/pr2/ausnahmen/finall/TryCatchFinallyExample.java +++ b/src/main/java/pr2/ausnahmen/finall/TryCatchFinallyExample.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.finall; +package pr2.exceptions.finall; import java.sql.Connection; import java.sql.ResultSet; diff --git a/src/main/java/pr2/ausnahmen/finall/TryCatchFinallyExample2.java b/src/main/java/pr2/ausnahmen/finall/TryCatchFinallyExample2.java index f7f9706..c4fb874 100644 --- a/src/main/java/pr2/ausnahmen/finall/TryCatchFinallyExample2.java +++ b/src/main/java/pr2/ausnahmen/finall/TryCatchFinallyExample2.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.finall; +package pr2.exceptions.finall; import java.sql.Connection; import java.sql.ResultSet; diff --git a/src/main/java/pr2/ausnahmen/junit/BrokenTest.java b/src/main/java/pr2/ausnahmen/junit/BrokenTest.java index 0ded0a7..aa06158 100644 --- a/src/main/java/pr2/ausnahmen/junit/BrokenTest.java +++ b/src/main/java/pr2/ausnahmen/junit/BrokenTest.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.junit; +package pr2.exceptions.junit; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/main/java/pr2/ausnahmen/junit/TestMitExpected.java b/src/main/java/pr2/ausnahmen/junit/TestMitExpected.java index 9514c12..68da666 100644 --- a/src/main/java/pr2/ausnahmen/junit/TestMitExpected.java +++ b/src/main/java/pr2/ausnahmen/junit/TestMitExpected.java @@ -1,4 +1,4 @@ -package pr2.ausnahmen.junit; +package pr2.exceptions.junit; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; diff --git a/src/main/java/pr2/ausnahmen/junit/TestMitTryCatch.java b/src/main/java/pr2/ausnahmen/junit/TestMitTryCatch.java index f5aa47a..1a964ac 100644 --- a/src/main/java/pr2/ausnahmen/junit/TestMitTryCatch.java +++ b/src/main/java/pr2/ausnahmen/junit/TestMitTryCatch.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.junit; +package pr2.exceptions.junit; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; diff --git a/src/main/java/pr2/ausnahmen/quiz/Finally.java b/src/main/java/pr2/ausnahmen/quiz/Finally.java index 1e8a962..a5b7e18 100644 --- a/src/main/java/pr2/ausnahmen/quiz/Finally.java +++ b/src/main/java/pr2/ausnahmen/quiz/Finally.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.quiz; +package pr2.exceptions.quiz; public class Finally { diff --git a/src/main/java/pr2/ausnahmen/trycatch/BlossNicht.java b/src/main/java/pr2/ausnahmen/trycatch/BlossNicht.java index 82a9abc..9a7654f 100644 --- a/src/main/java/pr2/ausnahmen/trycatch/BlossNicht.java +++ b/src/main/java/pr2/ausnahmen/trycatch/BlossNicht.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.trycatch; +package pr2.exceptions.trycatch; import java.io.FileInputStream; import java.io.IOException; diff --git a/src/main/java/pr2/ausnahmen/trycatch/ExceptionExample.java b/src/main/java/pr2/ausnahmen/trycatch/ExceptionExample.java index 99f835d..f1d9b78 100644 --- a/src/main/java/pr2/ausnahmen/trycatch/ExceptionExample.java +++ b/src/main/java/pr2/ausnahmen/trycatch/ExceptionExample.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.trycatch; +package pr2.exceptions.trycatch; public class ExceptionExample { diff --git a/src/main/java/pr2/ausnahmen/trycatch/FinallyMitSeiteneffekt.java b/src/main/java/pr2/ausnahmen/trycatch/FinallyMitSeiteneffekt.java index 88c958f..6df62f9 100644 --- a/src/main/java/pr2/ausnahmen/trycatch/FinallyMitSeiteneffekt.java +++ b/src/main/java/pr2/ausnahmen/trycatch/FinallyMitSeiteneffekt.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.ausnahmen.trycatch; +package pr2.exceptions.trycatch; public class FinallyMitSeiteneffekt { diff --git a/src/main/java/pr2/ausnahmen/trycatch/GanzBoese.java b/src/main/java/pr2/ausnahmen/trycatch/GanzBoese.java index 1ef4ad1..242d42d 100644 --- a/src/main/java/pr2/ausnahmen/trycatch/GanzBoese.java +++ b/src/main/java/pr2/ausnahmen/trycatch/GanzBoese.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.trycatch; +package pr2.exceptions.trycatch; public class GanzBoese { diff --git a/src/main/java/pr2/ausnahmen/trycatch/Netzwerk.java b/src/main/java/pr2/ausnahmen/trycatch/Netzwerk.java index 6b6beb4..c56d879 100644 --- a/src/main/java/pr2/ausnahmen/trycatch/Netzwerk.java +++ b/src/main/java/pr2/ausnahmen/trycatch/Netzwerk.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.ausnahmen.trycatch; +package pr2.exceptions.trycatch; import java.io.IOException; import java.net.InetSocketAddress; diff --git a/src/main/java/pr2/ausnahmen/trycatch/TryCatchExample.java b/src/main/java/pr2/ausnahmen/trycatch/TryCatchExample.java index f7ddf0a..f0d0803 100644 --- a/src/main/java/pr2/ausnahmen/trycatch/TryCatchExample.java +++ b/src/main/java/pr2/ausnahmen/trycatch/TryCatchExample.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.trycatch; +package pr2.exceptions.trycatch; import java.sql.Connection; import java.sql.ResultSet; diff --git a/src/main/java/pr2/ausnahmen/trycatch/TryCatchExampleZwei.java b/src/main/java/pr2/ausnahmen/trycatch/TryCatchExampleZwei.java index 9d9a1ef..bf33357 100644 --- a/src/main/java/pr2/ausnahmen/trycatch/TryCatchExampleZwei.java +++ b/src/main/java/pr2/ausnahmen/trycatch/TryCatchExampleZwei.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.trycatch; +package pr2.exceptions.trycatch; import java.io.FileNotFoundException; import java.io.IOException; diff --git a/src/main/java/pr2/ausnahmen/trycatch/polymorphie/A.java b/src/main/java/pr2/ausnahmen/trycatch/polymorphie/A.java index 2362e0c..ca278ab 100644 --- a/src/main/java/pr2/ausnahmen/trycatch/polymorphie/A.java +++ b/src/main/java/pr2/ausnahmen/trycatch/polymorphie/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.trycatch.polymorphie; +package pr2.exceptions.trycatch.polymorphie; import java.io.IOException; diff --git a/src/main/java/pr2/ausnahmen/trycatch/polymorphie/B.java b/src/main/java/pr2/ausnahmen/trycatch/polymorphie/B.java index e0affa3..2288efd 100644 --- a/src/main/java/pr2/ausnahmen/trycatch/polymorphie/B.java +++ b/src/main/java/pr2/ausnahmen/trycatch/polymorphie/B.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.ausnahmen.trycatch.polymorphie; +package pr2.exceptions.trycatch.polymorphie; import java.io.FileNotFoundException; import java.io.IOException; diff --git a/src/main/java/pr2/datenstrukturen/adt/BinaryTree.java b/src/main/java/pr2/datenstrukturen/adt/BinaryTree.java new file mode 100644 index 0000000..f201799 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/adt/BinaryTree.java @@ -0,0 +1,14 @@ +package pr2.datenstrukturen.adt; + +public class BinaryTree { + private TreeNode head; + private TreeNode nullNode; + + public BinaryTree() { + head = new TreeNode(null); + nullNode = new TreeNode(null); + head.setRight(nullNode); + nullNode.setLeft(nullNode); + nullNode.setRight(nullNode); + } +} diff --git a/src/main/java/pr2/datenstrukturen/adt/Queue.java b/src/main/java/pr2/datenstrukturen/adt/Queue.java new file mode 100644 index 0000000..df00b9d --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/adt/Queue.java @@ -0,0 +1,8 @@ +package pr2.datenstrukturen.adt; + +public interface Queue { + public void enter(Object obj) throws QueueException; + public Object leave() throws QueueException; + public Object front() throws QueueException; + public boolean isEmpty(); +} diff --git a/src/main/java/pr2/datenstrukturen/adt/QueueException.java b/src/main/java/pr2/datenstrukturen/adt/QueueException.java new file mode 100644 index 0000000..843a177 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/adt/QueueException.java @@ -0,0 +1,4 @@ +package pr2.datenstrukturen.adt; + +public class QueueException extends RuntimeException { +} diff --git a/src/main/java/pr2/datenstrukturen/adt/Stack.java b/src/main/java/pr2/datenstrukturen/adt/Stack.java new file mode 100644 index 0000000..3b7741b --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/adt/Stack.java @@ -0,0 +1,8 @@ +package pr2.datenstrukturen.adt; + +public interface Stack { + void push(Object obj) throws StackException; + Object pop() throws StackException; + Object top() throws StackException; + boolean isEmpty(); +} diff --git a/src/main/java/pr2/datenstrukturen/adt/StackException.java b/src/main/java/pr2/datenstrukturen/adt/StackException.java new file mode 100644 index 0000000..88e16bc --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/adt/StackException.java @@ -0,0 +1,4 @@ +package pr2.datenstrukturen.adt; + +public class StackException extends RuntimeException { +} diff --git a/src/main/java/pr2/datenstrukturen/adt/TreeNode.java b/src/main/java/pr2/datenstrukturen/adt/TreeNode.java new file mode 100644 index 0000000..88bca5a --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/adt/TreeNode.java @@ -0,0 +1,22 @@ +package pr2.datenstrukturen.adt; + +public class TreeNode { + TreeNode left = null; + TreeNode right = null; + + Object key; + + public TreeNode(Object o) { key = o; } + + public Object getKey() { return key; } + + public TreeNode getLeft() { return left; } + + public TreeNode getRight() { return right; } + + public void setLeft(TreeNode n) { left = n; } + + public void setRight(TreeNode n) { right = n; } + + public String toString() { return key.toString (); } +} diff --git a/src/main/java/pr2/datenstrukturen/avl/AVLTree.java b/src/main/java/pr2/datenstrukturen/avl/AVLTree.java new file mode 100644 index 0000000..2a1b427 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/avl/AVLTree.java @@ -0,0 +1,118 @@ +package pr2.datenstrukturen.avl; + +class Node { + int key, height; + Node left, right; + + public Node(int key) { + this.key = key; + height = 1; + } +} + +public class AVLTree { + Node root; + + int height(Node N) { + if (N == null) + return 0; + + return N.height; + } + + int max(int a, int b) { + return (a > b) ? a : b; + } + + Node rightRotate(Node y) { + Node x = y.left; + Node T2 = x.right; + + x.right = y; + y.left = T2; + + y.height = max(height(y.left), height(y.right)) + 1; + x.height = max(height(x.left), height(x.right)) + 1; + + return x; + } + + Node leftRotate(Node x) { + Node y = x.right; + Node T2 = y.left; + + y.left = x; + x.right = T2; + + x.height = max(height(x.left), height(x.right)) + 1; + y.height = max(height(y.left), height(y.right)) + 1; + + return y; + } + + int getBalance(Node N) { + if (N == null) + return 0; + + return height(N.left) - height(N.right); + } + + Node insert(Node node, int key) { + + if (node == null) + return (new Node(key)); + + if (key < node.key) + node.left = insert(node.left, key); + else if (key > node.key) + node.right = insert(node.right, key); + else + return node; + + node.height = 1 + max(height(node.left), + height(node.right)); + + int balance = getBalance(node); + + if (balance > 1 && key < node.left.key) + return rightRotate(node); + + if (balance < -1 && key > node.right.key) + return leftRotate(node); + + if (balance > 1 && key > node.left.key) { + node.left = leftRotate(node.left); + return rightRotate(node); + } + + if (balance < -1 && key < node.right.key) { + node.right = rightRotate(node.right); + return leftRotate(node); + } + + return node; + } + + void preOrder(Node node) { + if (node != null) { + System.out.print(node.key + " "); + preOrder(node.left); + preOrder(node.right); + } + } + public static void main(String[] args) { + AVLTree tree = new AVLTree(); + + /* Constructing tree given in the above figure */ + tree.root = tree.insert(tree.root, 10); + tree.root = tree.insert(tree.root, 20); + tree.root = tree.insert(tree.root, 30); + tree.root = tree.insert(tree.root, 40); + tree.root = tree.insert(tree.root, 50); + tree.root = tree.insert(tree.root, 25); + + System.out.println("Preorder traversal" + + " of constructed tree is : "); + tree.preOrder(tree.root); + } +} diff --git a/src/main/java/pr2/datenstrukturen/bt/BinaryTree.java b/src/main/java/pr2/datenstrukturen/bt/BinaryTree.java new file mode 100644 index 0000000..50b9624 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/bt/BinaryTree.java @@ -0,0 +1,66 @@ +package pr2.datenstrukturen.bt; + +class Node { + int data; + Node left; + Node right; + + public Node(int item) { + data = item; + left = right = null; + } +} + +public class BinaryTree { + // Wurzel des Baums + Node root; + + public BinaryTree() { + root = null; + } + + public void insert(int key) { + root = insertRec(root, key); + } + + private Node insertRec(Node root, int key) { + + if (root == null) { + root = new Node(key); + return root; + } + + if (key < root.data) + root.left = insertRec(root.left, key); + else if (key > root.data) + root.right = insertRec(root.right, key); + + return root; + } + + public void inorder() { + inorderRec(root); + } + + void inorderRec(Node root) { + if (root != null) { + inorderRec(root.left); + System.out.println(root.data); + inorderRec(root.right); + } + } + + public static void main(String[] args) { + BinaryTree tree = new BinaryTree(); + + tree.insert(50); + tree.insert(30); + tree.insert(20); + tree.insert(40); + tree.insert(70); + tree.insert(60); + tree.insert(80); + + tree.inorder(); + } +} diff --git a/src/main/java/pr2/datenstrukturen/bt/SimpleTree.java b/src/main/java/pr2/datenstrukturen/bt/SimpleTree.java new file mode 100644 index 0000000..4daf26d --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/bt/SimpleTree.java @@ -0,0 +1,94 @@ +package pr2.datenstrukturen.bt; + +import java.util.LinkedList; +import java.util.function.Consumer; + +public class SimpleTree { + private static class Node { + private Node left; + private Node right; + private String data; + + public Node(String data, Node left, Node right) { + this.left = left; + this.right = right; + this.data = data; + } + + public Node(String data) { + this.left = null; + this.right = null; + this.data = data; + } + } + + private Node root; + + public SimpleTree(Node root) { + this.root = root; + } + + public void preorder(Consumer f) { + preorder(f, this.root); + } + + public void preorder(Consumer f, Node node) { + if (node == null) return; + f.accept(node.data); // Aktion auf dem Knoten ausführen + preorder(f, node.left); // Linker Teilbaum + preorder(f, node.right); // Rechter Teilbaum + } + + public void inorder(Consumer f) { + inorder(f, this.root); + } + + public void inorder(Consumer f, Node node) { + if (node == null) return; + preorder(f, node.left); // Linker Teilbaum + f.accept(node.data); // Aktion auf dem Knoten ausführen + preorder(f, node.right); // Rechter Teilbaum + } + + public void postorder(Consumer f) { + postorder(f, this.root); + } + + public void postorder(Consumer f, Node node) { + if (node == null) return; + postorder(f, node.left); // Linker Teilbaum + postorder(f, node.right); // Rechter Teilbaum + f.accept(node.data); // Aktion auf dem Knoten ausführen + } + + public void levelorder(Consumer f) { + var list = new LinkedList(); + list.add(root); + while (!list.isEmpty()) { + Node n = list.pollFirst(); + f.accept(n.data); // Aktion ausführen + if (n.left != null) { + list.add(n.left); + } + if (n.right != null) { + list.add(n.right); + } + } + } + + public static void main(String[] args) { + SimpleTree t = new SimpleTree( + new Node("A", + new Node("B", new Node("D"), new Node("E")), + new Node("C", new Node("F"), new Node("G")))); + + System.out.print("Pre-Order: "); + t.preorder(System.out::print); + System.out.print("\nIn-Order: "); + t.inorder(System.out::print); + System.out.print("\nPost-Order: "); + t.postorder(System.out::print); + System.out.print("\nLevel-Order: "); + t.levelorder(System.out::print); + } +} diff --git a/src/main/java/pr2/datenstrukturen/buffer/RingBuffer.java b/src/main/java/pr2/datenstrukturen/buffer/RingBuffer.java new file mode 100644 index 0000000..af760d5 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/buffer/RingBuffer.java @@ -0,0 +1,55 @@ +package pr2.datenstrukturen.buffer; + +public class RingBuffer { + private T[] elements; + private int head = 0; + private int tail = 0; + private int size = 0; + + public RingBuffer(int capacity) { + elements = (T[]) new Object[capacity]; + } + + // Element hinzufügen + public void add(T element) { + if (size == elements.length) { + head = (head + 1) % elements.length; + } else { + size++; + } + elements[tail] = element; + tail = (tail + 1) % elements.length; + } + + // erstes Element zurückgeben + public T first() { + if (size == 0) { + return null; + } + return elements[head]; + } + + // letztes Element zurückgeben + public T last() { + if (size == 0) { + return null; + } + return elements[(tail - 1 + elements.length) % elements.length]; + } + + // Puffer leer? + public boolean isEmpty() { + return size == 0; + } + + // Puffer voll? + public boolean isFull() { + return size == elements.length; + } + + // Anzahl der Elemente im Puffer + public int size() { + return size; + } +} + diff --git a/src/main/java/pr2/datenstrukturen/graph/Graph.java b/src/main/java/pr2/datenstrukturen/graph/Graph.java new file mode 100644 index 0000000..af51748 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/graph/Graph.java @@ -0,0 +1,54 @@ +package pr2.datenstrukturen.graph; + +import java.util.LinkedList; + +class Graph { + private int V; // Anzahl der Knoten + private LinkedList adj[]; // Adjazenzliste + + Graph(int v) { + V = v; + adj = new LinkedList[v]; + for (int i=0; i true + System.out.println(sh.contains("Januar")); // -> true + + } +} diff --git a/src/main/java/pr2/datenstrukturen/hash/HashTable.java b/src/main/java/pr2/datenstrukturen/hash/HashTable.java new file mode 100644 index 0000000..8d491b0 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/hash/HashTable.java @@ -0,0 +1,51 @@ +package pr2.datenstrukturen.hash; + +import java.util.LinkedList; + +public class HashTable { + private int SIZE = 10; + private LinkedList[] table; + + HashTable() { + table = new LinkedList[SIZE]; + for (int i = 0; i < SIZE; i++) + table[i] = new LinkedList(); + } + + public void put(int key, int value) { + int index = hash(key); + table[index].add(new Node(key, value)); + } + + public int get(int key) { + int index = hash(key); + for (Node node : table[index]) + if (node.key == key) + return node.value; + return -1; + } + + public void remove(int key) { + int index = hash(key); + for (Node node : table[index]) + if (node.key == key) { + table[index].remove(node); + break; + } + } + + private int hash(int key) { + return key % SIZE; + } + + private static class Node { + int key; + int value; + + public Node(int key, int value) { + this.key = key; + this.value = value; + } + } +} + diff --git a/src/main/java/pr2/datenstrukturen/hash/SimpleHashTable.java b/src/main/java/pr2/datenstrukturen/hash/SimpleHashTable.java new file mode 100644 index 0000000..876be70 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/hash/SimpleHashTable.java @@ -0,0 +1,45 @@ +package pr2.datenstrukturen.hash; + +public class SimpleHashTable { + + private static final int SIZE = 10; + private final String[] buckets = new String[SIZE]; + + public int idx(String s) { + return Math.abs(s.hashCode()) % SIZE; + } + public void add(String s) { + buckets[idx(s)] = s; + } + + public void remove(String s) { + buckets[idx(s)] = null; + } + + public boolean contains(String s) { + return s.equals(buckets[idx(s)]); + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < SIZE; i++) { + sb.append(String.format("[%d]: %s\n", i, + buckets[i] == null ? "" : buckets[i])); + } + return sb.toString(); + } + + public static void main(String[] args) { + SimpleHashTable sh = new SimpleHashTable(); + sh.add("Januar"); + sh.add("Februar"); + sh.add("März"); + sh.add("April"); + sh.add("Mai"); + + System.out.println(sh.toString()); + System.out.println(sh.contains("Februar")); + System.out.println(sh.contains("Januar")); + + } +} diff --git a/src/main/java/pr2/datenstrukturen/liste/ArrayIterator.java b/src/main/java/pr2/datenstrukturen/liste/ArrayIterator.java new file mode 100644 index 0000000..ab6c7d6 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/ArrayIterator.java @@ -0,0 +1,24 @@ +package pr2.datenstrukturen.liste; + +public class ArrayIterator { + + private final int[] array; + private int pos; + + public ArrayIterator(int[] array) { + this.array = array.clone(); + pos = 0; + } + + public boolean hasNext() { + return pos < array.length; + } + + public int next() { + return array[pos++]; // ArrayIndexOutOfBoundsException + } + + public void reset() { + pos = 0; + } +} diff --git a/src/main/java/pr2/datenstrukturen/liste/ArrayIteratorTest.java b/src/main/java/pr2/datenstrukturen/liste/ArrayIteratorTest.java new file mode 100644 index 0000000..263ffa3 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/ArrayIteratorTest.java @@ -0,0 +1,14 @@ +package pr2.datenstrukturen.liste; + +public class ArrayIteratorTest { + + public static void main(String[] args) { + int[] array = { 1, 2, 3, 4, 5, 6, 7, 8 }; + ArrayIterator ai1 = new ArrayIterator(array); + ArrayIterator ai2 = new ArrayIterator(array); + + while (ai1.hasNext()) { + System.out.println(ai1.next()); + } + } +} diff --git a/src/main/java/pr2/datenstrukturen/liste/DoubleLinkedList.java b/src/main/java/pr2/datenstrukturen/liste/DoubleLinkedList.java new file mode 100644 index 0000000..8c0d276 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/DoubleLinkedList.java @@ -0,0 +1,112 @@ +package pr2.datenstrukturen.liste; + + +class DoubleLinkedList implements IntList { + + private static class Node { + int data; + Node next; + Node prev; + + Node(int data) { + this.data = data; + this.next = null; + this.prev = null; + } + } + + Node head; + Node tail; + + + + + public void append(int data) { + Node newNode = new Node(data); + + if (head == null) { + head = newNode; + tail = newNode; + return; + } + + tail.next = newNode; + newNode.prev = tail; + tail = newNode; + } + + public void prepend(int data) { + Node newNode = new Node(data); + + if (head == null) { + head = newNode; + tail = newNode; + return; + } + + newNode.next = head; + head.prev = newNode; + head = newNode; + } + + public void deleteWithValue(int data) { + if (head == null) { + return; + } + + if (head.data == data) { + head = head.next; + head.prev = null; + return; + } + + Node current = head; + while (current.next != null) { + if (current.next.data == data) { + current.next = current.next.next; + if (current.next != null) { + current.next.prev = current; + } + return; + } + current = current.next; + } + } + + public void printList() { + Node current = head; + while (current != null) { + System.out.print(current.data + " "); + current = current.next; + } + System.out.println(); + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("[ "); + + Node current = head; + while (current != null) { + sb.append(current.data); + current = current.next; + if (current != null) { + sb.append(", "); + } + } + + sb.append(" ]"); + return sb.toString(); + } + + public int size() { + Node current = head; + int count = 0; + while (current != null) { + count++; + current = current.next; + } + return count; + } +} + diff --git a/src/main/java/pr2/datenstrukturen/liste/IntList.java b/src/main/java/pr2/datenstrukturen/liste/IntList.java new file mode 100644 index 0000000..a806e75 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/IntList.java @@ -0,0 +1,9 @@ +package pr2.datenstrukturen.liste; + +public interface IntList { + void append(int data); + + void prepend(int data); + + int size(); +} diff --git a/src/main/java/pr2/datenstrukturen/liste/LinkedList.java b/src/main/java/pr2/datenstrukturen/liste/LinkedList.java new file mode 100644 index 0000000..cbed4db --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/LinkedList.java @@ -0,0 +1,120 @@ +package pr2.datenstrukturen.liste; + +class LinkedList implements IntList { + + private static class Node { + int data; + Node next; + + public Node(int data) { + this.data = data; + this.next = null; + } + } + + Node head; + + private Node last() { + Node result = head; + + while (result != null && result.next != null) { + result = result.next; + } + + return result; + } + + public void append(int data) { + Node newNode = new Node(data); + Node last = last(); + + if (last == null) { + head = newNode; + } + else { + last.next = newNode; + } + } + + public void prepend(int data) { + Node newNode = new Node(data); + + if (head == null) { + head = newNode; + return; + } + + newNode.next = head; + head = newNode; + } + + public int size() { + Node current = head; + int count = 0; + while (current != null) { + count++; + current = current.next; + } + return count; + } + + public int remove(int index) { + Node current = head; + Node prev = head; + + if (current == null) { + throw new RuntimeException("List is empty"); + } + + if (index >= size()) { + throw new IndexOutOfBoundsException(); + } + + int count = 0; + while (current != null) { + if (index == count) { + int data = current.data; + prev.next = current.next; + return data; + } + prev = current; + current = current.next; + } + return count; + } + public void delete(int data) { + Node current = head, prev = null; + if (current != null && current.data == data) { + head = current.next; + return; + } + + while (current != null && current.data != data) { + prev = current; + current = current.next; + } + + if (current == null) + return; + + prev.next = current.next; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("[ "); + + Node current = head; + while (current != null) { + sb.append(current.data); + current = current.next; + if (current != null) { + sb.append(", "); + } + } + + sb.append(" ]"); + return sb.toString(); + } +} diff --git a/src/main/java/pr2/datenstrukturen/liste/Pr2LinkedList.java b/src/main/java/pr2/datenstrukturen/liste/Pr2LinkedList.java new file mode 100644 index 0000000..a1a74a0 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/Pr2LinkedList.java @@ -0,0 +1,168 @@ +package pr2.datenstrukturen.liste; + +public class Pr2LinkedList implements Pr2List { + + /** Start node. */ + private Pr2Node first; + + /** Last Node. */ + private Pr2Node last; + + @Override + public void add(T e) { + if (first == null) { + first = new Pr2Node<>(e); + last = first; + } + else { + last.next = new Pr2Node<>(e); + last = last.next; + } + } + + private Pr2Node at(int index) { + + if (index == 0 && first != null) { + return first; + } + + Pr2Node n = first; + int count = 0; + while (n != null) { + if (count == index) { + return n; + } + n = n.next; + count++; + } + + throw new ArrayIndexOutOfBoundsException(); + } + + @Override + public T get(int index) { + // no negative indices + if (index < 0) { + throw new ArrayIndexOutOfBoundsException("Negative index"); + } + + return at(index).element; + } + + @Override + public T remove(int index) { + T e; + + // no negative indices + if (index < 0) { + throw new ArrayIndexOutOfBoundsException("Negative index"); + } + + // Case first node + if (index == 0 && first != null) { + if (last == first) { + last = null; + } + e = first.element; + first = first.next; + return e; + } + + + Pr2Node prevNode = at(index - 1); + if (prevNode.next == null) { + // index not present + throw new ArrayIndexOutOfBoundsException(); + } + + e = prevNode.next.element; + prevNode.next = prevNode.next.next; + + if (prevNode.next == null) { + last = prevNode; + } + + return e; + } + + @Override + public int length() { + Pr2Node n = first; + int count = 0; + while (n != null) { + n = n.next; + count++; + } + return count; + } + + @Override + public T removeLast() { + T e; + + if (last == null) { + throw new ArrayIndexOutOfBoundsException("Empty List"); + } + + if (first == last) { + e = last.element; + first = null; + last = null; + } + else { + Pr2Node n = first; + while (n.next != last) { + n = n.next; + } + e = n.next.element; + n.next = null; + last = n; + } + + return e; + } + + @Override + public T removeFirst() { + if (last == null) { + throw new ArrayIndexOutOfBoundsException("Empty List"); + } + + T e = first.element; + + if (first == last) { + first = null; + last = null; + } + else { + first = first.next; + } + + return e; + } + + @Override + public void free() { + first = null; + last = null; + } + + /** + * @see Object#toString() + */ + @Override + public String toString() { + StringBuilder b = new StringBuilder("[ "); + Pr2Node n = first; + + while (n != null) { + b.append(n.element); + b.append(", "); + n = n.next; + } + + b.append(']'); + + return b.toString(); + } +} diff --git a/src/main/java/pr2/datenstrukturen/liste/Pr2LinkedListTest.java b/src/main/java/pr2/datenstrukturen/liste/Pr2LinkedListTest.java new file mode 100644 index 0000000..2c29939 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/Pr2LinkedListTest.java @@ -0,0 +1,124 @@ +package pr2.datenstrukturen.liste; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Testklasse für die Listen. + */ +public class Pr2LinkedListTest { + @Test + public void testLength() { + Pr2List list = new Pr2LinkedList<>(); + + assertEquals(0, list.length()); + list.add("A"); + assertEquals(1, list.length()); + list.add("B"); + assertEquals(2, list.length()); + list.removeLast(); + assertEquals(1, list.length()); + list.removeLast(); + assertEquals(0, list.length()); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + list::removeLast); + assertEquals(0, list.length()); + list.add("A"); + assertEquals(1, list.length()); + list.add("B"); + } + + @Test + public void testAddRemove() { + Pr2List list = new Pr2LinkedList<>(); + + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + list::removeLast); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.remove(0)); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.remove(1)); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.remove(-1)); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.remove(99)); + + list.add("A"); + assertEquals("A", list.removeLast()); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + list::removeLast); + + list.add("A"); + list.add("B"); + list.add("C"); + assertEquals("A", list.removeFirst()); + assertEquals("C", list.removeLast()); + assertEquals("B", list.removeLast()); + assertEquals(0, list.length()); + + list.add("A"); + list.add("B"); + list.add("C"); + assertEquals("A", list.remove(0)); + assertEquals("B", list.removeFirst()); + assertEquals("C", list.remove(0)); + assertEquals(0, list.length()); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.remove(0)); + + list.add("A"); + list.add("B"); + list.add("C"); + list.add("D"); + list.add("E"); + System.out.println(list); + assertEquals("C", list.remove(2)); + list.add("F"); + assertEquals("D", list.remove(2)); + assertEquals("F", list.get(3)); + assertEquals("E", list.remove(2)); + assertEquals("A", list.remove(0)); + assertEquals("B", list.remove(0)); + assertEquals("F", list.remove(0)); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.remove(0)); + + list.add("A"); + assertEquals("A", list.remove(0)); + } + + @Test + public void testGet() { + Pr2List list = new Pr2LinkedList<>(); + + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.get(0)); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.get(-9)); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.get(999)); + + list.add("A"); + assertEquals("A", list.get(0)); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.get(1)); + + list.add("B"); + assertEquals("A", list.get(0)); + assertEquals("B", list.get(1)); + Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, + () -> list.get(2)); + + list.free(); + assertEquals(0, list.length()); + + list.add("A"); + list.add("B"); + list.add("C"); + assertEquals("C", list.get(2)); + assertEquals("A", list.get(0)); + assertEquals("B", list.get(1)); + } +} diff --git a/src/main/java/pr2/datenstrukturen/liste/Pr2List.java b/src/main/java/pr2/datenstrukturen/liste/Pr2List.java new file mode 100644 index 0000000..fb26ba7 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/Pr2List.java @@ -0,0 +1,61 @@ +package pr2.datenstrukturen.liste; + +/** + * Interface für eine Liste. + * + * @param Tyo der gespeicherten Daten. + */ +public interface Pr2List { + + /** + * Fügt das Element e an das Ende der Liste an. + * + * @param e das anzufügende Element + */ + void add(T e); + + /** + * Liefert das Element an der gegebenen Position zurück. + * + * @param index Index des Elements. + * @return das gefundene Element. + * @throws IndexOutOfBoundsException wenn der Index zu groß + * oder zu klein ist + */ + T get(int index); + + /** + * Entfernt das Element an der gegebenen Stelle. + * + * @param index der Index, des Elements. + * @return Das entfernte Element. + * @throws IndexOutOfBoundsException wenn der Index zu groß + * oder zu klein ist + */ + T remove(int index); + + /** + * Gibt die Länge der Liste zurück. + * @return Länge der Liste. + */ + int length(); + + /** + * Entfernt das letzte Element aus der Liste. + * @return Das entfernte Element. + * @throws IndexOutOfBoundsException wenn die Liste leer ist + */ + T removeLast(); + + /** + * Entfernt das erste Element aus der Liste. + * @return Das entfernte Element. + * @throws IndexOutOfBoundsException wenn die Liste leer ist + */ + T removeFirst(); + + /** + * Leert die komplette Liste. + */ + void free(); +} diff --git a/src/main/java/pr2/datenstrukturen/liste/Pr2Node.java b/src/main/java/pr2/datenstrukturen/liste/Pr2Node.java new file mode 100644 index 0000000..f6c7dd0 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/Pr2Node.java @@ -0,0 +1,23 @@ +package pr2.datenstrukturen.liste; + +/** + * Ein Knoten in der Liste. + * + * @param Tyo der gespeicherten Daten. + */ +public class Pr2Node { + + /** + * Das gespeicherte Element. + */ + T element; + + /** + * Der Nachfolger. + */ + Pr2Node next; + + public Pr2Node(T e) { + element = e; + } +} diff --git a/src/main/java/pr2/datenstrukturen/liste/TestLists.java b/src/main/java/pr2/datenstrukturen/liste/TestLists.java new file mode 100644 index 0000000..54e90fa --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/liste/TestLists.java @@ -0,0 +1,31 @@ +package pr2.datenstrukturen.liste; + +public class TestLists { + + public static void main(String[] args) { + IntList ll = new LinkedList(); + + ll.append(1); + ll.append(2); + ll.append(3); + ll.append(4); + ll.append(5); + ll.prepend(0); + + System.out.println(ll); + System.out.println(ll.size()); + + IntList dll = new DoubleLinkedList(); + + dll.append(1); + dll.append(2); + dll.append(3); + dll.append(4); + dll.append(5); + dll.prepend(0); + + System.out.println(dll); + System.out.println(dll.size()); + + } +} diff --git a/src/main/java/pr2/datenstrukturen/queue/Queue.java b/src/main/java/pr2/datenstrukturen/queue/Queue.java new file mode 100644 index 0000000..d2e18a0 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/queue/Queue.java @@ -0,0 +1,42 @@ +package pr2.datenstrukturen.queue; + +import java.util.LinkedList; + +public class Queue { + private LinkedList elements; + + public Queue() { + elements = new LinkedList(); + } + + // Element in die Queue legen + public void enqueue(T element) { + elements.addLast(element); + } + + // erstes Element aus der Queue entfernen und zurückgeben + public T dequeue() { + if (elements.isEmpty()) { + return null; + } + return elements.removeFirst(); + } + + // erstes Element zurückgeben, ohne es zu entfernen + public T peek() { + if (elements.isEmpty()) { + return null; + } + return elements.getFirst(); + } + + // Queue leer? + public boolean isEmpty() { + return elements.isEmpty(); + } + + // Anzahl der Elemente in der Queue + public int size() { + return elements.size(); + } +} diff --git a/src/main/java/pr2/datenstrukturen/search/BoyerMoore.java b/src/main/java/pr2/datenstrukturen/search/BoyerMoore.java new file mode 100644 index 0000000..787a4b0 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/search/BoyerMoore.java @@ -0,0 +1,52 @@ +package pr2.datenstrukturen.search; + +public class BoyerMoore { + + private final int R; // the radix + private int[] right; // the bad-character skip array + + private char[] pattern; // store the pattern as a character array + private String pat; // or as a string + + public BoyerMoore(String pat) { + this.R = 256; + this.pat = pat; + + // position of rightmost occurrence of c in the pattern + right = new int[R]; + for (int c = 0; c < R; c++) + right[c] = -1; + for (int j = 0; j < pat.length(); j++) + right[pat.charAt(j)] = j; + } + + public int search(String txt) { + int M = pat.length(); + int N = txt.length(); + int skip; + for (int i = 0; i <= N - M; i += skip) { + skip = 0; + for (int j = M-1; j >= 0; j--) { + if (pat.charAt(j) != txt.charAt(i+j)) { + skip = Math.max(1, j - right[txt.charAt(i+j)]); + break; + } + } + if (skip == 0) return i; // found + } + return N; // not found + } + + public static void main(String[] args) { + String txt = "This is a simple example text"; + String pat = "example"; + BoyerMoore bm = new BoyerMoore(pat); + int offset = bm.search(txt); + // print results + System.out.println("text: " + txt); + System.out.print("pattern: "); + for (int i = 0; i < offset; i++) + System.out.print(" "); + System.out.println(pat); + } +} diff --git a/src/main/java/pr2/datenstrukturen/search/KMP.java b/src/main/java/pr2/datenstrukturen/search/KMP.java new file mode 100644 index 0000000..2bdfb01 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/search/KMP.java @@ -0,0 +1,38 @@ +package pr2.datenstrukturen.search; + +public class KMP { + private final int[] prefixFunction; + private final String pattern; + + public KMP(String pattern) { + this.pattern = pattern; + prefixFunction = new int[pattern.length()]; + int j = 0; + for (int i = 1; i < pattern.length(); i++) { + while (j > 0 && pattern.charAt(i) != pattern.charAt(j)) { + j = prefixFunction[j - 1]; + } + if (pattern.charAt(i) == pattern.charAt(j)) { + j++; + } + prefixFunction[i] = j; + } + } + + public int search(String text) { + int j = 0; + for (int i = 0; i < text.length(); i++) { + while (j > 0 && text.charAt(i) != pattern.charAt(j)) { + j = prefixFunction[j - 1]; + } + if (text.charAt(i) == pattern.charAt(j)) { + j++; + } + if (j == pattern.length()) { + return i - pattern.length() + 1; + } + } + return -1; + } +} + diff --git a/src/main/java/pr2/datenstrukturen/stack/Stack.java b/src/main/java/pr2/datenstrukturen/stack/Stack.java new file mode 100644 index 0000000..dc29f69 --- /dev/null +++ b/src/main/java/pr2/datenstrukturen/stack/Stack.java @@ -0,0 +1,42 @@ +package pr2.datenstrukturen.stack; + +import java.util.ArrayList; + +public class Stack { + private final ArrayList elements; + + public Stack() { + elements = new ArrayList(); + } + + // Element auf den Stack legen + public void push(T element) { + elements.add(element); + } + + // oberstes Element vom Stack entfernen und zurückgeben + public T pop() { + if (elements.isEmpty()) { + return null; + } + return elements.remove(elements.size() - 1); + } + + // oberstes Element zurückgeben, ohne es zu entfernen + public T peek() { + if (elements.isEmpty()) { + return null; + } + return elements.get(elements.size() - 1); + } + + // Stack leer? + public boolean isEmpty() { + return elements.isEmpty(); + } + + // Anzahl der Elemente im Stack + public int size() { + return elements.size(); + } +} diff --git a/src/main/java/pr2/ds/avl/AVLTree.java b/src/main/java/pr2/ds/avl/AVLTree.java index 64f128d..2a1b427 100644 --- a/src/main/java/pr2/ds/avl/AVLTree.java +++ b/src/main/java/pr2/ds/avl/AVLTree.java @@ -1,4 +1,4 @@ -package pr2.ds.avl; +package pr2.datenstrukturen.avl; class Node { int key, height; diff --git a/src/main/java/pr2/ds/bt/BinaryTree.java b/src/main/java/pr2/ds/bt/BinaryTree.java index c882614..50b9624 100644 --- a/src/main/java/pr2/ds/bt/BinaryTree.java +++ b/src/main/java/pr2/ds/bt/BinaryTree.java @@ -1,4 +1,4 @@ -package pr2.ds.bt; +package pr2.datenstrukturen.bt; class Node { int data; diff --git a/src/main/java/pr2/ds/bt/SimpleTree.java b/src/main/java/pr2/ds/bt/SimpleTree.java index f7fd5a8..4daf26d 100644 --- a/src/main/java/pr2/ds/bt/SimpleTree.java +++ b/src/main/java/pr2/ds/bt/SimpleTree.java @@ -1,4 +1,4 @@ -package pr2.ds.bt; +package pr2.datenstrukturen.bt; import java.util.LinkedList; import java.util.function.Consumer; diff --git a/src/main/java/pr2/ds/buffer/RingBuffer.java b/src/main/java/pr2/ds/buffer/RingBuffer.java index 1c35668..af760d5 100644 --- a/src/main/java/pr2/ds/buffer/RingBuffer.java +++ b/src/main/java/pr2/ds/buffer/RingBuffer.java @@ -1,4 +1,4 @@ -package pr2.ds.buffer; +package pr2.datenstrukturen.buffer; public class RingBuffer { private T[] elements; diff --git a/src/main/java/pr2/ds/graph/Graph.java b/src/main/java/pr2/ds/graph/Graph.java index cbaefa8..af51748 100644 --- a/src/main/java/pr2/ds/graph/Graph.java +++ b/src/main/java/pr2/ds/graph/Graph.java @@ -1,4 +1,4 @@ -package pr2.ds.graph; +package pr2.datenstrukturen.graph; import java.util.LinkedList; diff --git a/src/main/java/pr2/ds/hash/BetterHashTable.java b/src/main/java/pr2/ds/hash/BetterHashTable.java index 8f87772..222398c 100644 --- a/src/main/java/pr2/ds/hash/BetterHashTable.java +++ b/src/main/java/pr2/ds/hash/BetterHashTable.java @@ -1,4 +1,4 @@ -package pr2.ds.hash; +package pr2.datenstrukturen.hash; import java.util.LinkedList; diff --git a/src/main/java/pr2/ds/hash/HashTable.java b/src/main/java/pr2/ds/hash/HashTable.java index e389c68..8d491b0 100644 --- a/src/main/java/pr2/ds/hash/HashTable.java +++ b/src/main/java/pr2/ds/hash/HashTable.java @@ -1,4 +1,4 @@ -package pr2.ds.hash; +package pr2.datenstrukturen.hash; import java.util.LinkedList; diff --git a/src/main/java/pr2/ds/hash/SimpleHashTable.java b/src/main/java/pr2/ds/hash/SimpleHashTable.java index 721191d..876be70 100644 --- a/src/main/java/pr2/ds/hash/SimpleHashTable.java +++ b/src/main/java/pr2/ds/hash/SimpleHashTable.java @@ -1,4 +1,4 @@ -package pr2.ds.hash; +package pr2.datenstrukturen.hash; public class SimpleHashTable { diff --git a/src/main/java/pr2/ds/liste/ArrayIterator.java b/src/main/java/pr2/ds/liste/ArrayIterator.java index 455a21f..ab6c7d6 100644 --- a/src/main/java/pr2/ds/liste/ArrayIterator.java +++ b/src/main/java/pr2/ds/liste/ArrayIterator.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; public class ArrayIterator { diff --git a/src/main/java/pr2/ds/liste/ArrayIteratorTest.java b/src/main/java/pr2/ds/liste/ArrayIteratorTest.java index 7f3a1ee..263ffa3 100644 --- a/src/main/java/pr2/ds/liste/ArrayIteratorTest.java +++ b/src/main/java/pr2/ds/liste/ArrayIteratorTest.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; public class ArrayIteratorTest { diff --git a/src/main/java/pr2/ds/liste/DoubleLinkedList.java b/src/main/java/pr2/ds/liste/DoubleLinkedList.java index 440d81a..8c0d276 100644 --- a/src/main/java/pr2/ds/liste/DoubleLinkedList.java +++ b/src/main/java/pr2/ds/liste/DoubleLinkedList.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; class DoubleLinkedList implements IntList { diff --git a/src/main/java/pr2/ds/liste/IntList.java b/src/main/java/pr2/ds/liste/IntList.java index 3298e52..a806e75 100644 --- a/src/main/java/pr2/ds/liste/IntList.java +++ b/src/main/java/pr2/ds/liste/IntList.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; public interface IntList { void append(int data); diff --git a/src/main/java/pr2/ds/liste/LinkedList.java b/src/main/java/pr2/ds/liste/LinkedList.java index 16d4bf7..cbed4db 100644 --- a/src/main/java/pr2/ds/liste/LinkedList.java +++ b/src/main/java/pr2/ds/liste/LinkedList.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; class LinkedList implements IntList { diff --git a/src/main/java/pr2/ds/liste/Pr2LinkedList.java b/src/main/java/pr2/ds/liste/Pr2LinkedList.java index cf4f615..a1a74a0 100644 --- a/src/main/java/pr2/ds/liste/Pr2LinkedList.java +++ b/src/main/java/pr2/ds/liste/Pr2LinkedList.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; public class Pr2LinkedList implements Pr2List { diff --git a/src/main/java/pr2/ds/liste/Pr2LinkedListTest.java b/src/main/java/pr2/ds/liste/Pr2LinkedListTest.java index c6e4426..2c29939 100644 --- a/src/main/java/pr2/ds/liste/Pr2LinkedListTest.java +++ b/src/main/java/pr2/ds/liste/Pr2LinkedListTest.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/src/main/java/pr2/ds/liste/Pr2List.java b/src/main/java/pr2/ds/liste/Pr2List.java index f8b9394..fb26ba7 100644 --- a/src/main/java/pr2/ds/liste/Pr2List.java +++ b/src/main/java/pr2/ds/liste/Pr2List.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; /** * Interface für eine Liste. diff --git a/src/main/java/pr2/ds/liste/Pr2Node.java b/src/main/java/pr2/ds/liste/Pr2Node.java index 59e6f28..f6c7dd0 100644 --- a/src/main/java/pr2/ds/liste/Pr2Node.java +++ b/src/main/java/pr2/ds/liste/Pr2Node.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; /** * Ein Knoten in der Liste. diff --git a/src/main/java/pr2/ds/liste/TestLists.java b/src/main/java/pr2/ds/liste/TestLists.java index b240627..54e90fa 100644 --- a/src/main/java/pr2/ds/liste/TestLists.java +++ b/src/main/java/pr2/ds/liste/TestLists.java @@ -1,4 +1,4 @@ -package pr2.ds.liste; +package pr2.datenstrukturen.liste; public class TestLists { diff --git a/src/main/java/pr2/ds/queue/Queue.java b/src/main/java/pr2/ds/queue/Queue.java index 97569aa..d2e18a0 100644 --- a/src/main/java/pr2/ds/queue/Queue.java +++ b/src/main/java/pr2/ds/queue/Queue.java @@ -1,4 +1,4 @@ -package pr2.ds.queue; +package pr2.datenstrukturen.queue; import java.util.LinkedList; diff --git a/src/main/java/pr2/ds/search/BoyerMoore.java b/src/main/java/pr2/ds/search/BoyerMoore.java index b3ffc06..787a4b0 100644 --- a/src/main/java/pr2/ds/search/BoyerMoore.java +++ b/src/main/java/pr2/ds/search/BoyerMoore.java @@ -1,4 +1,4 @@ -package pr2.ds.search; +package pr2.datenstrukturen.search; public class BoyerMoore { diff --git a/src/main/java/pr2/ds/search/KMP.java b/src/main/java/pr2/ds/search/KMP.java index ebd67f6..2bdfb01 100644 --- a/src/main/java/pr2/ds/search/KMP.java +++ b/src/main/java/pr2/ds/search/KMP.java @@ -1,4 +1,4 @@ -package pr2.ds.search; +package pr2.datenstrukturen.search; public class KMP { private final int[] prefixFunction; diff --git a/src/main/java/pr2/ds/stack/Stack.java b/src/main/java/pr2/ds/stack/Stack.java index 47d0bfa..dc29f69 100644 --- a/src/main/java/pr2/ds/stack/Stack.java +++ b/src/main/java/pr2/ds/stack/Stack.java @@ -1,4 +1,4 @@ -package pr2.ds.stack; +package pr2.datenstrukturen.stack; import java.util.ArrayList; diff --git a/src/main/java/pr2/enumerationen/records/newstyle/Rectangle.java b/src/main/java/pr2/enumerationen/records/newstyle/Rectangle.java new file mode 100644 index 0000000..942b319 --- /dev/null +++ b/src/main/java/pr2/enumerationen/records/newstyle/Rectangle.java @@ -0,0 +1,26 @@ +package pr2.enumerationen.records.newstyle; + +record Rectangle(double length, double width) { + public Rectangle { + if (length <= 0 || width <= 0) { + throw new java.lang.IllegalArgumentException( + String.format("Invalid dimensions: %f, %f", length, width)); + } + } + + public double length() { + return length; + } + + public double area() { + return length * width; + } +} + +class Demo { + public static void main(String[] args) { + Rectangle r = new Rectangle(4, 3); + System.out.println("Fläche: " + r.length() * r.width()); + System.out.println("Fläche: " + r.area()); + } +} diff --git a/src/main/java/pr2/enumerationen/records/plain/Rectangle.java b/src/main/java/pr2/enumerationen/records/plain/Rectangle.java new file mode 100644 index 0000000..5646053 --- /dev/null +++ b/src/main/java/pr2/enumerationen/records/plain/Rectangle.java @@ -0,0 +1,55 @@ +package pr2.enumerationen.records.plain; + +public final class Rectangle { + + private final double length; + private final double width; + + public Rectangle(double length, double width) { + this.length = length; + this.width = width; + } + + public double length() { return this.length; } + public double width() { return this.width; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + Rectangle rectangle = (Rectangle) o; + + if (Double.compare(rectangle.length, length) != 0) { + return false; + } + return Double.compare(rectangle.width, width) == 0; + } + + @Override + public int hashCode() { + int result; + long temp; + temp = Double.doubleToLongBits(length); + result = (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(width); + result = 31 * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public String toString() { + return "Rechteck{" + "length=" + length + ", width=" + width + '}'; + } +} + +class Demo { + public static void main(String[] args) { + Rectangle r = new Rectangle(4, 3); + System.out.println("Fläche: " + r.length() * r.width()); + } +} diff --git a/src/main/java/pr2/exceptions/Java7.java b/src/main/java/pr2/exceptions/Java7.java new file mode 100644 index 0000000..c7565b7 --- /dev/null +++ b/src/main/java/pr2/exceptions/Java7.java @@ -0,0 +1,118 @@ +/* (c) 2022 Thomas Smits */ +package pr2.exceptions; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * + * + * @author Thomas Smits + */ +public class Java7 { + + /** + * @param args the command line arguments. + */ + public static void main(String[] args) { + + String titel = "Noob"; + + switch (titel) { + case "Manager": + break; + + case "Senior": + break; + + default: + break; + } + + List list = new ArrayList<>(); + Map map = new HashMap<>(); + Set set = new HashSet<>(); + + new Java7().catchThrow(); + + try { + openFile(); + writeToDatabase(); + } + catch (FileNotFoundException | SQLException e) { + System.out.println("Ohje, alles kapput...:" + e); + } + } + + public static void openFile() throws FileNotFoundException { + throw new FileNotFoundException(); + } + + public static void writeToDatabase() throws SQLException { + throw new SQLException(); + } + + + public void catchThrow() { + try { + try { + openFile(); + } + catch (IOException e) { + throw e; + } + } + catch (Exception e) { + System.out.println(e.getClass()); + } + } + + + public void resources() { + try(FileInputStream fis = new FileInputStream("/tmp/file1"); + FileOutputStream fos = new FileOutputStream("/tmp/file2")) { + + int i = fis.read(); + fos.write(i); + } + catch (IOException e) { + // Ausnahme behandeln + } + } + + + public void resourcesOld() throws IOException { + + FileInputStream fis = new FileInputStream("/tmp/file1"); + FileOutputStream fos = new FileOutputStream("/tmp/file2"); + + try { + int i = fis.read(); + fos.write(i); + } + catch (IOException e) { + // Ausnahme behandeln + } + finally { + try { + fis.close(); + } + catch (IOException e) { /* ignore */ } + + try { + fos.close(); + } + catch (IOException e) { /* ignore */ } + } + } + +} diff --git a/src/main/java/pr2/exceptions/callstack/CallStack1.java b/src/main/java/pr2/exceptions/callstack/CallStack1.java new file mode 100644 index 0000000..6ab6c54 --- /dev/null +++ b/src/main/java/pr2/exceptions/callstack/CallStack1.java @@ -0,0 +1,40 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.callstack; + +import java.io.FileInputStream; +import java.io.IOException; + +public class CallStack1 { + + public static void main(String[] args) { + + if (args.length < 1) { + System.err.println("Bitte Dateinamen angeben."); + System.exit(4); + } + + + try { + mergeData(args[0], "/tmp/output"); + } catch (IOException e) { + System.err.printf("Datei %s gibt es nicht%n%n", args[0]); + } + } + + public static void mergeData(String inFile, String outFile) + throws IOException { + writeData(inFile, outFile); + } + + public static void writeData(String inFile, String outFile) throws IOException { + aggregate(5, 5, inFile); + } + + public static int aggregate(int a, int b, String inFile) throws IOException { + FileInputStream f = new FileInputStream(inFile); + f.close(); + return 1; + } +} diff --git a/src/main/java/pr2/exceptions/callstack/CallStack2.java b/src/main/java/pr2/exceptions/callstack/CallStack2.java new file mode 100644 index 0000000..6815ceb --- /dev/null +++ b/src/main/java/pr2/exceptions/callstack/CallStack2.java @@ -0,0 +1,29 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.callstack; + +import java.io.FileInputStream; +import java.io.IOException; + +public class CallStack2 { + + public static void main(String[] args) throws IOException { + mergeData("/tmp/input", "/tmp/output"); + } + + public static void mergeData(String inFile, String outFile) + throws IOException { + writeData(outFile); + } + + public static void writeData(String outFile) throws IOException { + aggregate(5, 5); + } + + public static int aggregate(int a, int b) throws IOException { + FileInputStream f = new FileInputStream("/tmp/input"); + f.close(); + return 1; + } +} diff --git a/src/main/java/pr2/exceptions/callstack/CallStack3.java b/src/main/java/pr2/exceptions/callstack/CallStack3.java new file mode 100644 index 0000000..7d618cc --- /dev/null +++ b/src/main/java/pr2/exceptions/callstack/CallStack3.java @@ -0,0 +1,29 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.callstack; + +import java.io.FileInputStream; +import java.io.IOException; + +public class CallStack3 { + + public static void main(String[] args) throws IOException { + mergeData(args[0], "/tmp/output"); + } + + public static void mergeData(String inFile, String outFile) + throws IOException { + writeData(inFile, outFile); + } + + public static void writeData(String inFile, String outFile) throws IOException { + aggregate(5, 5, inFile); + } + + public static int aggregate(int a, int b, String inFile) throws IOException { + FileInputStream f = new FileInputStream(inFile); + f.close(); + return 1; + } +} diff --git a/src/main/java/pr2/exceptions/callstack/HandleOrDeclare.java b/src/main/java/pr2/exceptions/callstack/HandleOrDeclare.java new file mode 100644 index 0000000..3bff015 --- /dev/null +++ b/src/main/java/pr2/exceptions/callstack/HandleOrDeclare.java @@ -0,0 +1,53 @@ + +package pr2.exceptions.callstack; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.sql.SQLException; + +/** + * @author Thomas Smits + */ +public class HandleOrDeclare { + + public void openFile(String dateiName) + throws IOException, FileNotFoundException { + // Datei öffnen + } + + public void datenSchreiben(String dateiName, String sqlStatement) + throws FileNotFoundException, IOException, SQLException { + + openFile(dateiName); + // Mit Datenbank arbeiten + } + + public void dateiAnlegen(String dateiName) + throws FileNotFoundException, IOException { + + try { + datenSchreiben(dateiName, "SELECT * FROM x"); + } + catch (SQLException ex) { + // Datenbank Problem beheben ;-) + } + } + + public void userInterface() { + String dateiName = askUser(); + + try { + dateiAnlegen(dateiName); + } + catch (FileNotFoundException ex) { + // Benutzer erneut nach namen Fragen + } + catch (IOException ex) { + // Benutzer auf Problem hinweisen + } + } + + public String askUser() { + return null; + } +} diff --git a/src/main/java/pr2/exceptions/eigene/Client.java b/src/main/java/pr2/exceptions/eigene/Client.java new file mode 100644 index 0000000..7846140 --- /dev/null +++ b/src/main/java/pr2/exceptions/eigene/Client.java @@ -0,0 +1,26 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.eigene; + +public class Client { + + public void doIt() { + + try { + Server.connect("server1", 22); + } + catch (ServerException e1) { + System.err.println("Keine Verbindung zum server " + + e1.getHost() + " auf Port " + e1.getPort()); + + try { + Server.connect("server2", 22); + } + catch (ServerException e2) { + System.err.println("Ersatzserver geht auch nicht: " + + e2.getHost() + " auf Port " + e2.getPort()); + } + } + } +} diff --git a/src/main/java/pr2/exceptions/eigene/Server.java b/src/main/java/pr2/exceptions/eigene/Server.java new file mode 100644 index 0000000..3a41a5d --- /dev/null +++ b/src/main/java/pr2/exceptions/eigene/Server.java @@ -0,0 +1,21 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.eigene; + +public class Server { + + public static void connect(String host, int port) throws ServerException { + + int result = connectInternal(host, port); + + if (result == -1) { + throw new ServerException("Cannot connect to " + host + ":" + port, host, port); + } + + // ... + + } + + private static native int connectInternal(String host, int port); +} diff --git a/src/main/java/pr2/exceptions/eigene/ServerException.java b/src/main/java/pr2/exceptions/eigene/ServerException.java new file mode 100644 index 0000000..b5b0d35 --- /dev/null +++ b/src/main/java/pr2/exceptions/eigene/ServerException.java @@ -0,0 +1,24 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.eigene; + +public class ServerException extends Exception { + + private int port; + private String host; + + public ServerException(String message, String host, int port) { + super(message); + this.host = host; + this.port = port; + } + + public int getPort() { + return port; + } + + public String getHost() { + return host; + } +} diff --git a/src/main/java/pr2/exceptions/eigene/SimpleExample2.java b/src/main/java/pr2/exceptions/eigene/SimpleExample2.java new file mode 100644 index 0000000..2a098a0 --- /dev/null +++ b/src/main/java/pr2/exceptions/eigene/SimpleExample2.java @@ -0,0 +1,27 @@ +/* (c) 2022 Thomas Smits */ +package pr2.exceptions.eigene; + +import java.io.IOException; + +public class SimpleExample2 { + + public static void main(String[] args) { + new SimpleExample2().method(); + } + + public void method() { + try { + System.out.println("A"); + thrower(); + System.out.println("B"); + } + catch (IOException e) { + System.out.println("Fehler: " + e.getMessage()); + } + } + + + private void thrower() throws IOException { + throw new IOException("Festplatte explodiert"); + } +} diff --git a/src/main/java/pr2/exceptions/eigene/SimpleExamples.java b/src/main/java/pr2/exceptions/eigene/SimpleExamples.java new file mode 100644 index 0000000..28319c2 --- /dev/null +++ b/src/main/java/pr2/exceptions/eigene/SimpleExamples.java @@ -0,0 +1,25 @@ +/* (c) 2022 Thomas Smits */ +package pr2.exceptions.eigene; + +import java.io.IOException; + +public class SimpleExamples { + + public static void main(String[] args) { + + boolean b = true; + + try { + System.out.println("A"); + + if (b) { + throw new IOException("Festplatte abgebrannt"); + } + + System.out.println("B"); + } + catch (IOException e) { + System.out.println("Fehler: " + e.getMessage()); + } + } +} diff --git a/src/main/java/pr2/exceptions/finall/TryCatchFinallyExample.java b/src/main/java/pr2/exceptions/finall/TryCatchFinallyExample.java new file mode 100644 index 0000000..1d3e041 --- /dev/null +++ b/src/main/java/pr2/exceptions/finall/TryCatchFinallyExample.java @@ -0,0 +1,46 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.finall; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class TryCatchFinallyExample { + + public static void main(String[] args) { + + Connection connection = getConnection(); + + try { + ResultSet rs = readData(connection); + + while (rs.next()) { + // Daten bearbeiten + } + + return; + } + catch (SQLException ex) { + // Datenbank Problem behandeln + } + finally { + releaseConnection(connection); + } + + } + + private static ResultSet readData(Connection connection) throws SQLException { + return null; + } + + private static Connection getConnection() { + return null; + } + + private static void releaseConnection(Connection connection) { + + } + +} diff --git a/src/main/java/pr2/exceptions/finall/TryCatchFinallyExample2.java b/src/main/java/pr2/exceptions/finall/TryCatchFinallyExample2.java new file mode 100644 index 0000000..c4fb874 --- /dev/null +++ b/src/main/java/pr2/exceptions/finall/TryCatchFinallyExample2.java @@ -0,0 +1,51 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.finall; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class TryCatchFinallyExample2 { + + public static void main(String[] args) { + + Connection connection = getConnection(); + + try { + ResultSet rs = readData(connection); + + while (rs.next()) { + // Daten bearbeiten + } + + return; + } + catch (SQLException ex) { + // Datenbank Problem behandeln + } + finally { + try { + releaseConnection(connection); + } + catch (SQLException ex) { + // Hier kann man nichts mehr machen + } + } + + } + + private static ResultSet readData(Connection connection) throws SQLException { + return null; + } + + private static Connection getConnection() { + return null; + } + + private static void releaseConnection(Connection connection) throws SQLException { + + } + +} diff --git a/src/main/java/pr2/exceptions/junit/BrokenTest.java b/src/main/java/pr2/exceptions/junit/BrokenTest.java new file mode 100644 index 0000000..aa06158 --- /dev/null +++ b/src/main/java/pr2/exceptions/junit/BrokenTest.java @@ -0,0 +1,25 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.junit; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Assertions; + +public class BrokenTest { + + @Test + public void testKaputt() { + String s1 = new String("Hallo"); + assertEquals("Hallo", s1); + + Assertions.assertThrows(NullPointerException.class, () -> { + new String((String) null); + new String((char[]) null); + }); + + String s3 = new String("World"); + assertEquals("world", s3); + } +} diff --git a/src/main/java/pr2/exceptions/junit/TestMitExpected.java b/src/main/java/pr2/exceptions/junit/TestMitExpected.java new file mode 100644 index 0000000..68da666 --- /dev/null +++ b/src/main/java/pr2/exceptions/junit/TestMitExpected.java @@ -0,0 +1,18 @@ +package pr2.exceptions.junit; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; + +/* + * (c) 2009 Thomas Smits + */ + +public class TestMitExpected { + + @Test + public void testAufAusnahme() { + Assertions.assertThrows(NullPointerException.class, () -> { + new String((String) null); + }); + } +} diff --git a/src/main/java/pr2/exceptions/junit/TestMitTryCatch.java b/src/main/java/pr2/exceptions/junit/TestMitTryCatch.java new file mode 100644 index 0000000..1a964ac --- /dev/null +++ b/src/main/java/pr2/exceptions/junit/TestMitTryCatch.java @@ -0,0 +1,25 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.junit; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; + +public class TestMitTryCatch { + + @Test + public void testAufAusnahme() { + + try { + new String((String) null); + fail(); + + } + catch (NullPointerException ex) { + assertTrue(true); + } + } +} diff --git a/src/main/java/pr2/exceptions/quiz/Finally.java b/src/main/java/pr2/exceptions/quiz/Finally.java new file mode 100644 index 0000000..a5b7e18 --- /dev/null +++ b/src/main/java/pr2/exceptions/quiz/Finally.java @@ -0,0 +1,21 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.quiz; + +public class Finally { + + @SuppressWarnings("finally") + public static boolean f() { + try { + return true; + } + finally { + return false; + } + } + + public static void main(String[] args) { + System.out.println(f()); + } +} diff --git a/src/main/java/pr2/exceptions/trycatch/BlossNicht.java b/src/main/java/pr2/exceptions/trycatch/BlossNicht.java new file mode 100644 index 0000000..9a7654f --- /dev/null +++ b/src/main/java/pr2/exceptions/trycatch/BlossNicht.java @@ -0,0 +1,42 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.trycatch; + +import java.io.FileInputStream; +import java.io.IOException; + +/** + * + * + * @author Thomas Smits + */ +public class BlossNicht { + + @SuppressWarnings("null") + public static void main(String[] args) throws IOException { + + try { + FileInputStream fis = new FileInputStream("/tmp/gibtsnicht"); + String s = null; + s = s.toUpperCase(); + fis.close(); + } + catch (Exception e) { + // Fehlerbehandlung + } + + FileInputStream fis = null; + + try { + fis = new FileInputStream("/tmp/gibtsnicht"); + } + catch (Exception e) { + e.printStackTrace(); + } + + fis.read(); + + + } +} diff --git a/src/main/java/pr2/exceptions/trycatch/ExceptionExample.java b/src/main/java/pr2/exceptions/trycatch/ExceptionExample.java new file mode 100644 index 0000000..f1d9b78 --- /dev/null +++ b/src/main/java/pr2/exceptions/trycatch/ExceptionExample.java @@ -0,0 +1,16 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.trycatch; + +public class ExceptionExample { + + public static void main(String[] args) { + + String[] namen = { "Franz", "Hans", "Alfons" }; + + for (int i = 0; i < 4; i++) { + System.out.print(namen[i] + ", "); + } + } +} diff --git a/src/main/java/pr2/exceptions/trycatch/FinallyMitSeiteneffekt.java b/src/main/java/pr2/exceptions/trycatch/FinallyMitSeiteneffekt.java new file mode 100644 index 0000000..6df62f9 --- /dev/null +++ b/src/main/java/pr2/exceptions/trycatch/FinallyMitSeiteneffekt.java @@ -0,0 +1,23 @@ +/* (c) 2022 Thomas Smits */ +package pr2.exceptions.trycatch; + +public class FinallyMitSeiteneffekt { + + private static int changeMe = 41; + + public static void main(String[] args) { + System.out.println(m()); + System.out.println(changeMe); + } + + @SuppressWarnings("finally") + static int m() { + try { + return changeMe++; + } + finally { + return changeMe++; + } + } + +} diff --git a/src/main/java/pr2/exceptions/trycatch/GanzBoese.java b/src/main/java/pr2/exceptions/trycatch/GanzBoese.java new file mode 100644 index 0000000..242d42d --- /dev/null +++ b/src/main/java/pr2/exceptions/trycatch/GanzBoese.java @@ -0,0 +1,22 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.trycatch; + +public class GanzBoese { + + public static void printArray(int[] array) { + + try { + for (int i = 0;;i++) { + System.out.println(array[i]); + } + } + catch (ArrayIndexOutOfBoundsException ex) { + } + } + + public static void main(String[] args) { + printArray(new int[] { 1,2,3,4,5,6,7,8,9,10 }); + } +} diff --git a/src/main/java/pr2/exceptions/trycatch/Netzwerk.java b/src/main/java/pr2/exceptions/trycatch/Netzwerk.java new file mode 100644 index 0000000..c56d879 --- /dev/null +++ b/src/main/java/pr2/exceptions/trycatch/Netzwerk.java @@ -0,0 +1,36 @@ +/* (c) 2022 Thomas Smits */ +package pr2.exceptions.trycatch; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketTimeoutException; + +/** + * Beispiel für Netzwerk-Verbindung mit Java-Fehlerbehandlung. + * + * @author Thomas Smits + */ +public class Netzwerk { + + @SuppressWarnings("resource") + public static void main(String[] args) { + + try { + ServerSocket servSocket = new ServerSocket(); + servSocket.bind(new InetSocketAddress(8080)); + + for (;;) { + Socket clntSocket = servSocket.accept(); + // ... + } + } + catch (SocketTimeoutException e) { + // Fehlerbehandlung + } + catch (IOException e) { + // Fehlerbehandlung + } + } +} diff --git a/src/main/java/pr2/exceptions/trycatch/TryCatchExample.java b/src/main/java/pr2/exceptions/trycatch/TryCatchExample.java new file mode 100644 index 0000000..f0d0803 --- /dev/null +++ b/src/main/java/pr2/exceptions/trycatch/TryCatchExample.java @@ -0,0 +1,40 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.trycatch; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class TryCatchExample { + + public static void main(String[] args) { + + Connection connection = getConnection(); + + try { + ResultSet rs = readData(connection); + + while (rs.next()) { + // Daten bearbeiten + } + } + catch (SQLException ex) { + // Datenbank Problem behandeln + String sqlStatus = ex.getSQLState(); + // ... + ex.printStackTrace(); + } + + } + + private static ResultSet readData(Connection connection) throws SQLException { + return null; + } + + private static Connection getConnection() { + return null; + } + +} diff --git a/src/main/java/pr2/exceptions/trycatch/TryCatchExampleZwei.java b/src/main/java/pr2/exceptions/trycatch/TryCatchExampleZwei.java new file mode 100644 index 0000000..bf33357 --- /dev/null +++ b/src/main/java/pr2/exceptions/trycatch/TryCatchExampleZwei.java @@ -0,0 +1,52 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.trycatch; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class TryCatchExampleZwei { + + public static void main(String[] args) { + + Connection connection = getConnection(); + + try { + ResultSet rs = readData(connection); + + while (rs.next()) { + storeToFile(rs.getString(0), rs); + } + } + catch (SQLException ex) { + // Datenbank-Problem + ex.printStackTrace(); + } + catch (FileNotFoundException ex) { + // Datei nicht gefunden + System.out.println(ex.getMessage()); + } + catch (IOException ex) { + // Allgemeiner IO-Fehler + System.out.println(ex.getMessage()); + } + + } + + private static ResultSet readData(Connection connection) throws SQLException { + return null; + } + + private static Connection getConnection() { + return null; + } + + public static void storeToFile(String fileName, ResultSet rs) throws FileNotFoundException, IOException {} + + + +} diff --git a/src/main/java/pr2/exceptions/trycatch/polymorphie/A.java b/src/main/java/pr2/exceptions/trycatch/polymorphie/A.java new file mode 100644 index 0000000..ca278ab --- /dev/null +++ b/src/main/java/pr2/exceptions/trycatch/polymorphie/A.java @@ -0,0 +1,12 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.trycatch.polymorphie; + +import java.io.IOException; + +public class A { + + public void method() throws IOException { + } +} diff --git a/src/main/java/pr2/exceptions/trycatch/polymorphie/B.java b/src/main/java/pr2/exceptions/trycatch/polymorphie/B.java new file mode 100644 index 0000000..2288efd --- /dev/null +++ b/src/main/java/pr2/exceptions/trycatch/polymorphie/B.java @@ -0,0 +1,31 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.exceptions.trycatch.polymorphie; + +import java.io.FileNotFoundException; +import java.io.IOException; + +class B extends A { + + public void method() throws IOException, FileNotFoundException { + } +} + +class C extends A { + + public void method() throws FileNotFoundException { + } +} + +class D extends A { + + public void method() { + } +} + +//class E extends A { +// +// public void method() throws SQLException { +// } +//} diff --git a/src/main/java/pr2/geschachtelte_klassen/MagicButton.java b/src/main/java/pr2/geschachtelte_klassen/MagicButton.java new file mode 100644 index 0000000..7e078b1 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/MagicButton.java @@ -0,0 +1,53 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +/** + * + * + * @author Thomas Smits + */ +public class MagicButton { + + public static void main(String[] args) { + final JFrame jf = new JFrame("Isch bin magisch"); + final JPanel jp = new JPanel(); + final JButton jb = new JButton("Click me!"); + final JButton jb2 = new JButton("Don't click me!"); + final JLabel jl = new JLabel("JLO"); + + jb.addActionListener((e) -> jl.setText("Can I haz cookies")); + + jb2.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + System.out.println("Don't press any buttons"); + } + }); + + jf.addWindowListener(new WindowAdapter() { + /** + * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent) + */ + @Override + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + jp.add(jb); + jp.add(jb2); + jp.add(jl); + jf.getContentPane().add(jp); + jf.pack(); + jf.setVisible(true); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/anonym/v1/AnonymBeispiel.java b/src/main/java/pr2/geschachtelte_klassen/anonym/v1/AnonymBeispiel.java new file mode 100644 index 0000000..bf40647 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/anonym/v1/AnonymBeispiel.java @@ -0,0 +1,17 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.anonym.v1; + + +public class AnonymBeispiel { + + public static void main(String[] args) { + + Object o = new Object() { + public String toString() { + return "Anonym..."; + } + }; + + System.out.println(o.toString()); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/anonym/v1/Escape.java b/src/main/java/pr2/geschachtelte_klassen/anonym/v1/Escape.java new file mode 100644 index 0000000..e632afa --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/anonym/v1/Escape.java @@ -0,0 +1,19 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.anonym.v1; + +public class Escape { + + public static Object escape() { + + return new Object() { + public String toString() { + return "Ich bin geflohen"; + } + }; + } + + public static void main(String[] args) { + Object o = Escape.escape(); + System.out.println(o.toString()); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/anonym/v1/Outer.java b/src/main/java/pr2/geschachtelte_klassen/anonym/v1/Outer.java new file mode 100644 index 0000000..f13088d --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/anonym/v1/Outer.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.anonym.v1; + +public class Outer { + + void methode() { + Object o = new Object() { }; + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/anonym/v2/Anonymous.java b/src/main/java/pr2/geschachtelte_klassen/anonym/v2/Anonymous.java new file mode 100644 index 0000000..39d76c8 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/anonym/v2/Anonymous.java @@ -0,0 +1,44 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.anonym.v2; + +import java.util.Date; + +public class Anonymous { + + public static void main(String[] args) { + + final String welt = "Welt"; + + A a = new A("Hallo") { + + Date date = new Date(); + + { + // Konstruktor der anonymen Klasse + this.s = this.s.toUpperCase() + " " + welt; + } + + @Override + public void methode() { + System.out.println(this.s + " am " + date); + } + + }; + + a.methode(); + } +} + +class A { + String s; + + public A(String s) { + this.s = s; + } + + public void methode() { + System.out.println(s); + } +} \ No newline at end of file diff --git a/src/main/java/pr2/geschachtelte_klassen/anonym/v2/Outer.java b/src/main/java/pr2/geschachtelte_klassen/anonym/v2/Outer.java new file mode 100644 index 0000000..0109db0 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/anonym/v2/Outer.java @@ -0,0 +1,40 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.anonym.v2; + +import java.util.Arrays; +import java.util.Comparator; + +public class Outer { + + private int i = 1; + + public void sortSpecial(String[] strings) { + + final int k = 1; + + Comparator c = new Comparator() { + + public int compare(String s1, String s2) { + int result = s1.toUpperCase().compareTo(s2.toUpperCase()); + result = result * i * k; + return result; + } + }; + + Arrays.sort(strings, c); + + Arrays.sort(strings, new Comparator() { + + public int compare(String s1, String s2) { + int result = s1.toUpperCase().compareTo(s2.toUpperCase()); + result = result * i * k; + return result; + } + }); + + Arrays.sort(strings, (s1, s2) -> s1.toUpperCase().compareTo(s2.toUpperCase())); + + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/anonym/v2/Outer2.java b/src/main/java/pr2/geschachtelte_klassen/anonym/v2/Outer2.java new file mode 100644 index 0000000..371ce0c --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/anonym/v2/Outer2.java @@ -0,0 +1,33 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.anonym.v2; + +import java.util.Arrays; +import java.util.Comparator; + +public class Outer2 { + + private int i; + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void sortSpecial(String[] strings) { + + final int k = 1; + + class DontCare implements Comparator { + + public int compare(Object o1, Object o2) { + String s1 = (String) o1; + String s2 = (String) o2; + int result = s1.toUpperCase().compareTo(s2.toUpperCase()); + result = result * i * k; + return result; + } + } + + Comparator c = new DontCare(); + + Arrays.sort(strings, c); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/anonym/v3/WasIstDennDas.java b/src/main/java/pr2/geschachtelte_klassen/anonym/v3/WasIstDennDas.java new file mode 100644 index 0000000..350f451 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/anonym/v3/WasIstDennDas.java @@ -0,0 +1,14 @@ +/* + * (c) 2010 Thomas Smits + */ +package pr2.geschachtelte_klassen.anonym.v3; + +import java.util.Date; + +public class WasIstDennDas { + + public static void main(String[] args) { + Date date = new Date() {{ setTime(400000000000L); }}; + System.out.println(date); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/anonym/A.java b/src/main/java/pr2/geschachtelte_klassen/basics/anonym/A.java new file mode 100644 index 0000000..38b7f52 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/anonym/A.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.anonym; + +class A { + + void methode() { + Object o = new Object() { }; + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/anzahl/A.java b/src/main/java/pr2/geschachtelte_klassen/basics/anzahl/A.java new file mode 100644 index 0000000..a1f0e28 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/anzahl/A.java @@ -0,0 +1,8 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.anzahl; + +public class A { + class B { } + class C { } + class D { } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/arten/A.java b/src/main/java/pr2/geschachtelte_klassen/basics/arten/A.java new file mode 100644 index 0000000..57f0745 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/arten/A.java @@ -0,0 +1,8 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.arten; + +class A { + abstract class B { } + interface C { } + class D { } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/local/A.java b/src/main/java/pr2/geschachtelte_klassen/basics/local/A.java new file mode 100644 index 0000000..2986d17 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/local/A.java @@ -0,0 +1,8 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.local; + +class A { + void methode() { + class B { } + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/priv/A.java b/src/main/java/pr2/geschachtelte_klassen/basics/priv/A.java new file mode 100644 index 0000000..054f182 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/priv/A.java @@ -0,0 +1,11 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.priv; + +class A { + + private int i = 12; + + class B { + private int k = i; + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/priv/C.java b/src/main/java/pr2/geschachtelte_klassen/basics/priv/C.java new file mode 100644 index 0000000..97320c4 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/priv/C.java @@ -0,0 +1,14 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.priv; + +class C { + + C() { + D d = new D(); + d.i = 100; + } + + class D { + private int i = 10; + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/sichtbarkeit/A.java b/src/main/java/pr2/geschachtelte_klassen/basics/sichtbarkeit/A.java new file mode 100644 index 0000000..98f65f5 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/sichtbarkeit/A.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.sichtbarkeit; + +class A { + private class B { } + class C { } + protected class D { } + public class E { } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/tiefe/A.java b/src/main/java/pr2/geschachtelte_klassen/basics/tiefe/A.java new file mode 100644 index 0000000..4e5ae15 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/tiefe/A.java @@ -0,0 +1,10 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.tiefe; + +class A { + class B { + class C { + class D { } + } + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/vererbung/A.java b/src/main/java/pr2/geschachtelte_klassen/basics/vererbung/A.java new file mode 100644 index 0000000..fb0eda1 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/vererbung/A.java @@ -0,0 +1,12 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.vererbung; + +import java.io.Serializable; +import java.util.ArrayList; + +class A { + class B { } + class C extends B { } + class D extends ArrayList { } + class E implements Serializable { } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/basics/vererbunginnen/A.java b/src/main/java/pr2/geschachtelte_klassen/basics/vererbunginnen/A.java new file mode 100644 index 0000000..85639ed --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/basics/vererbunginnen/A.java @@ -0,0 +1,6 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.basics.vererbunginnen; + +public class A { + class B extends A { } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/callback/Berechnung.java b/src/main/java/pr2/geschachtelte_klassen/callback/Berechnung.java new file mode 100644 index 0000000..741aaa4 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/callback/Berechnung.java @@ -0,0 +1,12 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.callback; + +public class Berechnung { + + public static int berechne(int input1, int input2, Funktion funktion) { + int ergebnis = funktion.apply(input1, input2); + return ergebnis; + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/callback/Funktion.java b/src/main/java/pr2/geschachtelte_klassen/callback/Funktion.java new file mode 100644 index 0000000..dcd8d06 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/callback/Funktion.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.callback; + +public interface Funktion { + public abstract int apply(int o1, int o2); +} diff --git a/src/main/java/pr2/geschachtelte_klassen/callback/TestBerechnung.java b/src/main/java/pr2/geschachtelte_klassen/callback/TestBerechnung.java new file mode 100644 index 0000000..d63ad75 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/callback/TestBerechnung.java @@ -0,0 +1,22 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.callback; + +public class TestBerechnung { + + public static void main(String[] args) { + + int ergebnis = Berechnung.berechne(7, 3, new Funktion() { + public int apply(int o1, int o2) { + return o1 - o2; + } + }); + + ergebnis = Berechnung.berechne(5, 6, new Funktion() { + public int apply(int o1, int o2) { + return o1 + o2; + } + }); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/decompiled/A$B.java b/src/main/java/pr2/geschachtelte_klassen/decompiled/A$B.java new file mode 100644 index 0000000..09f8bff --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/decompiled/A$B.java @@ -0,0 +1,24 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.decompiled; + +public class A$B { + private int i; + private int j; + + private void methodB(String s) { + i = A.access$0(this$0) + A.access$1(this$0) + j; // i = A.this.i + A.this.j + j; + A.access$2(this$0, "Welt"); // methodA("Welt"); + } + + public A$B(A a) { + this$0 = a; + } + + final A this$0; + static void access$0(A$B b, int i) { b.i = i; } + static void access$1(A$B b, String s) { b.methodB(s); } + static int access$2(A$B b) { return b.i; } + static int access$3(A$B b) { return b.j; } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/decompiled/A.java b/src/main/java/pr2/geschachtelte_klassen/decompiled/A.java new file mode 100644 index 0000000..c22145f --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/decompiled/A.java @@ -0,0 +1,23 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.decompiled; + +public class A { + + private int i; + private int j; + + public A() {} + + private int methodA(String s) { + A$B b = new A$B(this); // B b = new B(); + A$B.access$0(b, 5); // b.i = 5; + A$B.access$1(b, "Hallo"); // b.methodB("Hallo"); + return A$B.access$2(b) + A$B.access$3(b); // return b.i + b.j; + } + + static int access$0(A a) { return a.i; } + static int access$1(A a) { return a.j; } + static int access$2(A a, String s) { return a.methodA(s); } +} \ No newline at end of file diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/Aktion.java b/src/main/java/pr2/geschachtelte_klassen/lambda/Aktion.java new file mode 100644 index 0000000..a38f280 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/Aktion.java @@ -0,0 +1,32 @@ +package pr2.geschachtelte_klassen.lambda; + +@FunctionalInterface +public interface Aktion { + public void run(String param); +} + +class Main { + public static void main(String[] args) { + // Nur ein Statement, Block unnötig + Aktion a1 = s -> System.out.println(s); + + // Mehrere Statements, Block + Aktion a2 = s -> { + System.out.println(s); + System.out.println("Nochmal" + s); + }; + + a1.run("Hallo"); + } +} + + +class X { + public static void executor(Aktion a) { + a.run("Hallo"); + } + + public static void main(String[] args) { + executor(s -> System.out.println(s)); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/Berechnung.java b/src/main/java/pr2/geschachtelte_klassen/lambda/Berechnung.java new file mode 100644 index 0000000..36aad1f --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/Berechnung.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.lambda; + +public class Berechnung { + + public static int berechne(int input1, int input2, Funktion funktion) { + int ergebnis = funktion.apply(input1, input2); + + return ergebnis; + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/Capture.java b/src/main/java/pr2/geschachtelte_klassen/lambda/Capture.java new file mode 100644 index 0000000..9bd49ae --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/Capture.java @@ -0,0 +1,16 @@ +package pr2.geschachtelte_klassen.lambda; + +import java.util.Arrays; +import java.util.Comparator; + +public class Capture { + + public static void main(String[] args) { + int minus_eins = -1; + Comparator cmp = (a, b) -> a.compareTo(b) * minus_eins; + + String[] s = { "D", "A", "C", "B" }; + Arrays.sort(s, cmp); + System.out.println(Arrays.toString(s)); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/ComparatorFactory.java b/src/main/java/pr2/geschachtelte_klassen/lambda/ComparatorFactory.java new file mode 100644 index 0000000..f64a315 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/ComparatorFactory.java @@ -0,0 +1,20 @@ +package pr2.geschachtelte_klassen.lambda; + +import java.util.Comparator; + +public class ComparatorFactory { + + public Comparator createComparator() { + return (a, b) -> a.compareTo(b); + } + + public Comparator createComparatorClassic() { + return new Comparator() { + + @Override + public int compare(String a, String b) { + return a.compareTo(b); + } + }; + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/Funktion.java b/src/main/java/pr2/geschachtelte_klassen/lambda/Funktion.java new file mode 100644 index 0000000..7ddf366 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/Funktion.java @@ -0,0 +1,5 @@ +package pr2.geschachtelte_klassen.lambda; + +public interface Funktion { + public int apply(int a, int b); +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/Rechner.java b/src/main/java/pr2/geschachtelte_klassen/lambda/Rechner.java new file mode 100644 index 0000000..4655df1 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/Rechner.java @@ -0,0 +1,35 @@ +package pr2.geschachtelte_klassen.lambda; + + +public class Rechner { + public static void main(String[] args) { + int ergebnis = Berechnung.berechne(5, 7, new Funktion() { + + @Override + public int apply(int a, int b) { + return a + b; + } + }); + + System.out.println(ergebnis); + + Funktion add = new Funktion() { + @Override + public int apply(int a, int b) { + return a + b; + } + }; + + Funktion sub = new Funktion() { + @Override + public int apply(int a, int b) { + return a - b; + } + }; + + int e1 = add.apply(5, 5); + int e2 = sub.apply(10, 8); + + + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/RechnerLambda.java b/src/main/java/pr2/geschachtelte_klassen/lambda/RechnerLambda.java new file mode 100644 index 0000000..fe3865a --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/RechnerLambda.java @@ -0,0 +1,14 @@ +package pr2.geschachtelte_klassen.lambda; + +public class RechnerLambda { + public static void main(String[] args) { + int ergebnis = Berechnung.berechne(5, 5, (x, y) -> x + y); + System.out.println(ergebnis); + + Funktion add = (x, y) -> x + y; + Funktion sub = (x, y) -> x - y; + + int e1 = add.apply(5, 5); + int e2 = sub.apply(10, 8); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/Scoping.java b/src/main/java/pr2/geschachtelte_klassen/lambda/Scoping.java new file mode 100644 index 0000000..94e14a3 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/Scoping.java @@ -0,0 +1,17 @@ +package pr2.geschachtelte_klassen.lambda; + +public class Scoping { + + @Override + public String toString() { + return "Scoping"; + } + + public Runnable createRunner() { + return () -> System.out.println(toString()); + } + + public static void main(String[] args) { + new Scoping().createRunner().run(); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/Scoping2.java b/src/main/java/pr2/geschachtelte_klassen/lambda/Scoping2.java new file mode 100644 index 0000000..9867aa8 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/Scoping2.java @@ -0,0 +1,20 @@ +package pr2.geschachtelte_klassen.lambda; + +public class Scoping2 { + + @Override + public String toString() { + return "Scoping"; + } + + public Runnable createRunner() { + return new Runnable() { + public void run() { + System.out.println(toString()); } + }; + } + + public static void main(String[] args) { + new Scoping2().createRunner().run(); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/function/Rechner.java b/src/main/java/pr2/geschachtelte_klassen/lambda/function/Rechner.java new file mode 100644 index 0000000..4e93484 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/function/Rechner.java @@ -0,0 +1,20 @@ +package pr2.geschachtelte_klassen.lambda.function; + +import java.util.function.IntBinaryOperator; + +public class Rechner { + + public static int berechne(int input1, int input2, + IntBinaryOperator funktion) { + int ergebnis = funktion.applyAsInt(input1, input2); + return ergebnis; + } + + public static void main(String[] args) { + IntBinaryOperator sub = (a, b) -> a - b; + IntBinaryOperator add = (a, b) -> a + b; + + System.out.println(berechne(5, 3, sub)); + System.out.println(berechne(1, 7, add)); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/function/RechnerKurz.java b/src/main/java/pr2/geschachtelte_klassen/lambda/function/RechnerKurz.java new file mode 100644 index 0000000..2eae946 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/function/RechnerKurz.java @@ -0,0 +1,17 @@ +package pr2.geschachtelte_klassen.lambda.function; + +import java.util.function.IntBinaryOperator; + +public class RechnerKurz { + + public static int berechne(int input1, int input2, + IntBinaryOperator funktion) { + int ergebnis = funktion.applyAsInt(input1, input2); + return ergebnis; + } + + public static void main(String[] args) { + System.out.println(berechne(5, 3, (a, b) -> a - b)); + System.out.println(berechne(1, 7, (a, b) -> a + b)); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Funktion.java b/src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Funktion.java new file mode 100644 index 0000000..8df0176 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Funktion.java @@ -0,0 +1,9 @@ +package pr2.geschachtelte_klassen.lambda.methodref; + +public interface Funktion { + public int apply(int a, int b); + + public static int rechne(int a, int b, Funktion fkt) { + return fkt.apply(a, b); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Funktionssammlung.java b/src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Funktionssammlung.java new file mode 100644 index 0000000..d42ed76 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Funktionssammlung.java @@ -0,0 +1,12 @@ +package pr2.geschachtelte_klassen.lambda.methodref; + +public class Funktionssammlung { + + public static int add(int a, int b) { + return a + b; + } + + public static int sub(int a, int b) { + return a - b; + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Main.java b/src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Main.java new file mode 100644 index 0000000..7665741 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/methodref/Main.java @@ -0,0 +1,8 @@ +package pr2.geschachtelte_klassen.lambda.methodref; + +public class Main { + public static void main(String[] args) { + System.out.println(Funktion.rechne(5, 5, Funktionssammlung::add)); + System.out.println(Funktion.rechne(10, 8, Funktionssammlung::sub)); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/typing/Caller.java b/src/main/java/pr2/geschachtelte_klassen/lambda/typing/Caller.java new file mode 100644 index 0000000..8960405 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/typing/Caller.java @@ -0,0 +1,6 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.lambda.typing; + +public interface Caller { + public int call(); +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/typing/Runner.java b/src/main/java/pr2/geschachtelte_klassen/lambda/typing/Runner.java new file mode 100644 index 0000000..852404b --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/typing/Runner.java @@ -0,0 +1,6 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.lambda.typing; + +public interface Runner { + public void run(); +} diff --git a/src/main/java/pr2/geschachtelte_klassen/lambda/typing/TargetTyping.java b/src/main/java/pr2/geschachtelte_klassen/lambda/typing/TargetTyping.java new file mode 100644 index 0000000..5774efa --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/lambda/typing/TargetTyping.java @@ -0,0 +1,22 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.lambda.typing; + +public class TargetTyping { + public void doIt(Runner r) { + r.run(); + } + + public void doIt(Caller c) { + c.call(); + } + + public static void main(String[] args) { + TargetTyping t = new TargetTyping(); + + // implementiert Runner + t.doIt(() -> { return; }); + + // implementiert Caller + t.doIt(() -> { return 1; }); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/local/Escape.java b/src/main/java/pr2/geschachtelte_klassen/local/Escape.java new file mode 100644 index 0000000..98f1bee --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/local/Escape.java @@ -0,0 +1,20 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.local; + +public class Escape { + + public static Object escape() { + + class Papillon { + public String toString() { + return "Ich bin geflohen"; + } + } + + return new Papillon(); + } + + public static void main(String[] args) { + System.out.println(escape()); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/local/LocalBeispiel.java b/src/main/java/pr2/geschachtelte_klassen/local/LocalBeispiel.java new file mode 100644 index 0000000..c7d2064 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/local/LocalBeispiel.java @@ -0,0 +1,17 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.local; + +public class LocalBeispiel { + + public static void main(String[] args) { + + class LocalClass { + public String toString() { + return "Ich bin lokal"; + } + } + + LocalClass local = new LocalClass(); + System.out.println(local.toString()); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/local/LocalMitVariable.java b/src/main/java/pr2/geschachtelte_klassen/local/LocalMitVariable.java new file mode 100644 index 0000000..f1a368f --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/local/LocalMitVariable.java @@ -0,0 +1,19 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.local; + +public class LocalMitVariable { + + public static void main(String[] args) { + + final String ausgabe = "Ich bin lokal"; + + class LocalClass { + public String toString() { + return ausgabe; + } + } + + LocalClass local = new LocalClass(); + System.out.println(local); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/local/LocalMitVariableUndInstanz.java b/src/main/java/pr2/geschachtelte_klassen/local/LocalMitVariableUndInstanz.java new file mode 100644 index 0000000..24e4ba6 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/local/LocalMitVariableUndInstanz.java @@ -0,0 +1,21 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.local; + +public class LocalMitVariableUndInstanz { + + private String variable = "Ich bin nicht lokal"; + + public void doIt() { + + final String ausgabe = "Ich bin lokal"; + + class LocalClass { + public String toString() { + return ausgabe + ", " + variable; + } + } + + LocalClass local = new LocalClass(); + System.out.println(local); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/local/Outer.java b/src/main/java/pr2/geschachtelte_klassen/local/Outer.java new file mode 100644 index 0000000..a119f14 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/local/Outer.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.local; + +public class Outer { + + void methode() { + class Inner { } + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer.java new file mode 100644 index 0000000..bc8becd --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer.java @@ -0,0 +1,17 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.nonstatic.computer; + +public class Computer { + + String hersteller = "HP"; + + class Hauptspeicher { + int groesse = 1024; + } + + public static void main(String[] args) { + Computer computer = new Computer(); + Computer.Hauptspeicher h1 = computer.new Hauptspeicher(); + Computer.Hauptspeicher h2 = computer.new Hauptspeicher(); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer2.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer2.java new file mode 100644 index 0000000..90ed00d --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer2.java @@ -0,0 +1,16 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.nonstatic.computer; + +public class Computer2 { + + Hauptspeicher hauptspeicher = new Hauptspeicher(); + + class Hauptspeicher { + + Speicherzelle zelle = new Speicherzelle(); + + class Speicherzelle { + + } + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer3.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer3.java new file mode 100644 index 0000000..e43ff35 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer3.java @@ -0,0 +1,16 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.nonstatic.computer; + +public class Computer3 { + + String hersteller = "HP"; + Hauptspeicher speicher = new Hauptspeicher(); + + class Hauptspeicher { + int groesse = 1024; + + void printHersteller() { + System.out.println(Computer3.this.hersteller); + } + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer4.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer4.java new file mode 100644 index 0000000..cfb803f --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Computer4.java @@ -0,0 +1,34 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.nonstatic.computer; + +public class Computer4 { + + String hersteller = "HP"; + + class Hauptspeicher { + + int groesse = 1024; + + class Speicherzelle { + + int kapazitaet = 10; + + void doIt() { + System.out.println(Computer4.this.hersteller); + System.out.println(Hauptspeicher.this.groesse); + System.out.println(kapazitaet); + } + } + } +} + +class X { + public static void main(String[] args) { + Computer4 computer = new Computer4(); + Computer4.Hauptspeicher speicher = computer.new Hauptspeicher(); + Computer4.Hauptspeicher.Speicherzelle zelle = speicher.new Speicherzelle(); + + Computer4.Hauptspeicher.Speicherzelle z2 = new Computer4().new Hauptspeicher().new Speicherzelle(); + + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Outer.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Outer.java new file mode 100644 index 0000000..8914b43 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/computer/Outer.java @@ -0,0 +1,6 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.nonstatic.computer; + +public class Outer { + class Inner { } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/v1/Outer.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v1/Outer.java new file mode 100644 index 0000000..aaa22f5 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v1/Outer.java @@ -0,0 +1,24 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.nonstatic.v1; + +public class Outer { + + private int i = 0; + private int j = 5; + + public class Inner { + + public int doSomething(int i) { + Outer.this.i += i; + j++; + return Outer.this.i; + } + } + + public void testInner() { + Inner inner = new Inner(); + inner.doSomething(5); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/v1/UseOuter.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v1/UseOuter.java new file mode 100644 index 0000000..ccb9493 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v1/UseOuter.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.nonstatic.v1; + +public class UseOuter { + + public static void main(String[] args) { + Outer outer = new Outer(); + outer.testInner(); + + Outer.Inner inner = outer.new Inner(); + inner.doSomething(10); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/v2/Outer.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v2/Outer.java new file mode 100644 index 0000000..e24c360 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v2/Outer.java @@ -0,0 +1,25 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.nonstatic.v2; + +public class Outer { + + private int i; + + public void methode(int i) { + + final int j = 0; + + class Inner { + private int k; + + public void doSomething(int i) { + k = i + j + Outer.this.i; + } + } + + Inner inner = new Inner(); + inner.doSomething(i); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/v2/UseOuter.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v2/UseOuter.java new file mode 100644 index 0000000..fd903f8 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v2/UseOuter.java @@ -0,0 +1,12 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.nonstatic.v2; + +public class UseOuter { + + public static void main(String[] args) { + Outer outer = new Outer(); + outer.methode(5); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/nonstatic/v3/A.java b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v3/A.java new file mode 100644 index 0000000..b654492 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/nonstatic/v3/A.java @@ -0,0 +1,27 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.nonstatic.v3; + +public class A { + + private int i; + private int j; + + private class B { + private int i; + private int j; + + private void methodB(String s) { + i = A.this.i + A.this.j + j; + methodA("Welt"); + } + } + + private int methodA(String s) { + B b = new B(); + b.i = 5; + b.methodB("Hallo"); + return b.i + b.j; + } +} \ No newline at end of file diff --git a/src/main/java/pr2/geschachtelte_klassen/quiz/Outer.java b/src/main/java/pr2/geschachtelte_klassen/quiz/Outer.java new file mode 100644 index 0000000..82bb111 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/quiz/Outer.java @@ -0,0 +1,6 @@ +package pr2.geschachtelte_klassen.quiz; + +public class Outer { + public class Inner1 extends Outer {} + // public class Inner2 extends Inner1 {} +} diff --git a/src/main/java/pr2/geschachtelte_klassen/quiz/Twister.java b/src/main/java/pr2/geschachtelte_klassen/quiz/Twister.java new file mode 100644 index 0000000..113c1ba --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/quiz/Twister.java @@ -0,0 +1,25 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.quiz; + +public class Twister { + + private final String name; + + Twister(String name) { this.name = name; } + + private String name() { return name; } + + private void reproduce() { + new Twister("reproduce") { + void printName() { + System.out.println(name()); + } + }.printName(); + } + + public static void main(String[] args) { + new Twister("main").reproduce(); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/statisch/v1/Outer.java b/src/main/java/pr2/geschachtelte_klassen/statisch/v1/Outer.java new file mode 100644 index 0000000..5c70e00 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/statisch/v1/Outer.java @@ -0,0 +1,6 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.statisch.v1; + +public class Outer { + static class Inner { } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/statisch/v1/StaticMember.java b/src/main/java/pr2/geschachtelte_klassen/statisch/v1/StaticMember.java new file mode 100644 index 0000000..41e400f --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/statisch/v1/StaticMember.java @@ -0,0 +1,25 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.statisch.v1; + +public class StaticMember { + + public static class InnereKlasse { + + @Override + public String toString() { + return "Ich bin innen"; + } + } + + @Override + public String toString() { + return "Ich bin außen"; + } + + public static void main(String[] args) { + StaticMember aeussere = new StaticMember(); + StaticMember.InnereKlasse innere = new StaticMember.InnereKlasse(); + System.out.println(aeussere); // -> "Ich bin außen" + System.out.println(innere); // -> "Ich bin innen" + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/statisch/v2/Outer.java b/src/main/java/pr2/geschachtelte_klassen/statisch/v2/Outer.java new file mode 100644 index 0000000..01060af --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/statisch/v2/Outer.java @@ -0,0 +1,18 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.statisch.v2; + +public class Outer { + + private static int CONSTANT = 15; + + public static class Inner { + + public static final double PI = 3.14159265; + + public int doSomething(int i) { + return i * CONSTANT; + } + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/statisch/v2/PrivaterZugriff.java b/src/main/java/pr2/geschachtelte_klassen/statisch/v2/PrivaterZugriff.java new file mode 100644 index 0000000..994d984 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/statisch/v2/PrivaterZugriff.java @@ -0,0 +1,25 @@ +/* (c) 2022 Thomas Smits */ +package pr2.geschachtelte_klassen.statisch.v2; + +public class PrivaterZugriff { + + private static int a = 5; + + static class InnereKlasse { + + private static int b = 7; + + private static void innen() { + b = a; + aussen2(); + } + } + + private static void aussen1() { + InnereKlasse.innen(); + } + + private static void aussen2() { + InnereKlasse.b = 17; + } +} \ No newline at end of file diff --git a/src/main/java/pr2/geschachtelte_klassen/statisch/v2/UseOuter.java b/src/main/java/pr2/geschachtelte_klassen/statisch/v2/UseOuter.java new file mode 100644 index 0000000..a2350a9 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/statisch/v2/UseOuter.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.statisch.v2; + +public class UseOuter { + + public static void main(String[] args) { + Outer.Inner inner = new Outer.Inner(); + inner.doSomething(15); + double a = 2 * Outer.Inner.PI * 5.0 * 5.0; + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/statisch/v2/Zugriff.java b/src/main/java/pr2/geschachtelte_klassen/statisch/v2/Zugriff.java new file mode 100644 index 0000000..e3e7513 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/statisch/v2/Zugriff.java @@ -0,0 +1,29 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.statisch.v2; + +public class Zugriff { + + static class Inner1 { + private int i; + + private void doIt(Inner2 inner2) { + inner2.k++; + } + } + + static class Inner2 { + private int k; + + private void doIt(Inner1 inner1) { + inner1.i++; + } + } + + public void doIt(Inner1 i1, Inner2 i2) { + i1.i = i2.k; + i1.doIt(i2); + i2.doIt(i1); + } +} diff --git a/src/main/java/pr2/geschachtelte_klassen/vererbung/Outer.java b/src/main/java/pr2/geschachtelte_klassen/vererbung/Outer.java new file mode 100644 index 0000000..e015f62 --- /dev/null +++ b/src/main/java/pr2/geschachtelte_klassen/vererbung/Outer.java @@ -0,0 +1,37 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.geschachtelte_klassen.vererbung; + +public class Outer { + + protected String s; + private String t; + + protected void methode() { + System.out.println("Outer:methode()"); + } + + public class Inner extends Outer { + + protected void methode() { + System.out.println("Inner:methode()"); + } + + public void doIt() { + s = "geerbter String"; + Outer.this.s = "String von außen"; + t = "nicht über Vererbung sichtbar"; + Outer.this.methode(); + methode(); + } + } + + public static void main(String[] args) { + Outer o = new Outer(); + Outer.Inner i = o.new Inner(); + i.doIt(); + System.out.println(o.s); + System.out.println(i.s); + } +} \ No newline at end of file diff --git a/src/main/java/pr2/intro/junit/KomplexTest.java b/src/main/java/pr2/intro/junit/KomplexTest.java new file mode 100644 index 0000000..0fdb2d3 --- /dev/null +++ b/src/main/java/pr2/intro/junit/KomplexTest.java @@ -0,0 +1,63 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.intro.junit; + +public class KomplexTest { + + public void testAddition() { + KomplexeZahl k1 = new KomplexeZahl(3, 2); + KomplexeZahl k2 = new KomplexeZahl(5, 5); + + if (k1.addiere(k2).equals(new KomplexeZahl(8, 7))) { + System.out.println("OK: Addition"); + } + else { + System.err.println("Fehler: Addition"); + } + } + + public void testSubtraktion() { + KomplexeZahl k1 = new KomplexeZahl(5, 5); + KomplexeZahl k2 = new KomplexeZahl(3, 2); + + if (k1.subtrahiere(k2).equals(new KomplexeZahl(2, 3))) { + System.out.println("OK: Subtraktion"); + } + else { + System.err.println("Fehler: Subtraktion"); + } + } + + public void testMultiplikation() { + KomplexeZahl k1 = new KomplexeZahl(2, 5); + KomplexeZahl k2 = new KomplexeZahl(3, 7); + + if (k1.multipliziere(k2).equals(new KomplexeZahl(-29, 29))) { + System.out.println("OK: Multiplikation"); + } + else { + System.err.println("Fehler: Multiplikation"); + } + } + + public void testDivision() { + KomplexeZahl k1 = new KomplexeZahl(2, 5); + KomplexeZahl k2 = new KomplexeZahl(3, 7); + + if (k1.dividiere(k2).equals(new KomplexeZahl(41.0/58.0, 1.0/58.0))) { + System.out.println("OK: Division"); + } + else { + System.err.println("Fehler: Divison"); + } + } + + public static void main(String[] args) { + KomplexTest test = new KomplexTest(); + test.testAddition(); + test.testSubtraktion(); + test.testMultiplikation(); + test.testDivision(); + } +} diff --git a/src/main/java/pr2/intro/junit/KomplexeZahl.java b/src/main/java/pr2/intro/junit/KomplexeZahl.java new file mode 100644 index 0000000..99f8573 --- /dev/null +++ b/src/main/java/pr2/intro/junit/KomplexeZahl.java @@ -0,0 +1,87 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.intro.junit; + +public class KomplexeZahl { + + /** + * Realanteil. + */ + private double re; + + /** + * Imaginäranteil. + */ + private double im; + + /** + * Erzeugt eine neue Komplexe Zahl. + * + * @param re Realanteil + * @param im Imaginaeranteil + */ + public KomplexeZahl(double re, double im) { + this.re = re; + this.im = im; + } + + public double getRe() { + return re; + } + + public double getIm() { + return im; + } + + public KomplexeZahl addiere(KomplexeZahl z) { + return new KomplexeZahl(re + z.re, im + z.im); + } + + public KomplexeZahl subtrahiere(KomplexeZahl z) { + return new KomplexeZahl(re - z.re, im - z.im); + } + + public KomplexeZahl multipliziere(KomplexeZahl z) { + return new KomplexeZahl(re * z.re - im * z.im, re * z.im + im * z.re); + } + + public KomplexeZahl dividiere(KomplexeZahl z) { + return new KomplexeZahl( + (re * z.re + im * z.im) / (z.re * z.re + z.im * z.im), + (im * z.re - re * z.im) / (z.re * z.re + z.im * z.im)); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(im); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(re); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + KomplexeZahl other = (KomplexeZahl) obj; + if (Double.doubleToLongBits(im) != Double.doubleToLongBits(other.im)) + return false; + if (Double.doubleToLongBits(re) != Double.doubleToLongBits(other.re)) + return false; + return true; + } + + @Override + public String toString() { + return String.format("(%f, %fi)", re, im); + } +} diff --git a/src/main/java/pr2/intro/junit/KomplexeZahlTest.java b/src/main/java/pr2/intro/junit/KomplexeZahlTest.java new file mode 100644 index 0000000..32260ca --- /dev/null +++ b/src/main/java/pr2/intro/junit/KomplexeZahlTest.java @@ -0,0 +1,38 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.intro.junit; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; + +public class KomplexeZahlTest { + + @Test + public void testAddition() { + KomplexeZahl k1 = new KomplexeZahl(3, 2); + KomplexeZahl k2 = new KomplexeZahl(5, 5); + assertEquals(new KomplexeZahl(8, 7), k1.addiere(k2)); + } + + @Test + public void testSubtraktion() { + KomplexeZahl k1 = new KomplexeZahl(5, 5); + KomplexeZahl k2 = new KomplexeZahl(3, 2); + assertEquals(new KomplexeZahl(2, 3), k1.subtrahiere(k2)); + } + + @Test + public void testMultiplikation() { + KomplexeZahl k1 = new KomplexeZahl(2, 5); + KomplexeZahl k2 = new KomplexeZahl(3, 7); + assertEquals(new KomplexeZahl(-29, 29), k1.multipliziere(k2)); + } + + @Test + public void testDivision() { + KomplexeZahl k1 = new KomplexeZahl(2, 5); + KomplexeZahl k2 = new KomplexeZahl(3, 7); + assertEquals(new KomplexeZahl(41.0/58.0, 1.0/58.0), k1.dividiere(k2)); + } +} diff --git a/src/main/java/pr2/nestedclasses/MagicButton.java b/src/main/java/pr2/nestedclasses/MagicButton.java index e62f188..7e078b1 100644 --- a/src/main/java/pr2/nestedclasses/MagicButton.java +++ b/src/main/java/pr2/nestedclasses/MagicButton.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses; +package pr2.geschachtelte_klassen; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; diff --git a/src/main/java/pr2/nestedclasses/anonym/v1/AnonymBeispiel.java b/src/main/java/pr2/nestedclasses/anonym/v1/AnonymBeispiel.java index 50bf0bc..bf40647 100644 --- a/src/main/java/pr2/nestedclasses/anonym/v1/AnonymBeispiel.java +++ b/src/main/java/pr2/nestedclasses/anonym/v1/AnonymBeispiel.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.anonym.v1; +package pr2.geschachtelte_klassen.anonym.v1; public class AnonymBeispiel { diff --git a/src/main/java/pr2/nestedclasses/anonym/v1/Escape.java b/src/main/java/pr2/nestedclasses/anonym/v1/Escape.java index ea8b1ec..e632afa 100644 --- a/src/main/java/pr2/nestedclasses/anonym/v1/Escape.java +++ b/src/main/java/pr2/nestedclasses/anonym/v1/Escape.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.anonym.v1; +package pr2.geschachtelte_klassen.anonym.v1; public class Escape { diff --git a/src/main/java/pr2/nestedclasses/anonym/v1/Outer.java b/src/main/java/pr2/nestedclasses/anonym/v1/Outer.java index d6299af..f13088d 100644 --- a/src/main/java/pr2/nestedclasses/anonym/v1/Outer.java +++ b/src/main/java/pr2/nestedclasses/anonym/v1/Outer.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.anonym.v1; +package pr2.geschachtelte_klassen.anonym.v1; public class Outer { diff --git a/src/main/java/pr2/nestedclasses/anonym/v2/Anonymous.java b/src/main/java/pr2/nestedclasses/anonym/v2/Anonymous.java index 4657729..39d76c8 100644 --- a/src/main/java/pr2/nestedclasses/anonym/v2/Anonymous.java +++ b/src/main/java/pr2/nestedclasses/anonym/v2/Anonymous.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.anonym.v2; +package pr2.geschachtelte_klassen.anonym.v2; import java.util.Date; diff --git a/src/main/java/pr2/nestedclasses/anonym/v2/Outer.java b/src/main/java/pr2/nestedclasses/anonym/v2/Outer.java index fa4ef4c..0109db0 100644 --- a/src/main/java/pr2/nestedclasses/anonym/v2/Outer.java +++ b/src/main/java/pr2/nestedclasses/anonym/v2/Outer.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.anonym.v2; +package pr2.geschachtelte_klassen.anonym.v2; import java.util.Arrays; import java.util.Comparator; diff --git a/src/main/java/pr2/nestedclasses/anonym/v2/Outer2.java b/src/main/java/pr2/nestedclasses/anonym/v2/Outer2.java index 33ab6ec..371ce0c 100644 --- a/src/main/java/pr2/nestedclasses/anonym/v2/Outer2.java +++ b/src/main/java/pr2/nestedclasses/anonym/v2/Outer2.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.anonym.v2; +package pr2.geschachtelte_klassen.anonym.v2; import java.util.Arrays; import java.util.Comparator; diff --git a/src/main/java/pr2/nestedclasses/anonym/v3/WasIstDennDas.java b/src/main/java/pr2/nestedclasses/anonym/v3/WasIstDennDas.java index e6c1a94..350f451 100644 --- a/src/main/java/pr2/nestedclasses/anonym/v3/WasIstDennDas.java +++ b/src/main/java/pr2/nestedclasses/anonym/v3/WasIstDennDas.java @@ -1,7 +1,7 @@ /* * (c) 2010 Thomas Smits */ -package pr2.nestedclasses.anonym.v3; +package pr2.geschachtelte_klassen.anonym.v3; import java.util.Date; diff --git a/src/main/java/pr2/nestedclasses/basics/anonym/A.java b/src/main/java/pr2/nestedclasses/basics/anonym/A.java index fe7ea5c..38b7f52 100644 --- a/src/main/java/pr2/nestedclasses/basics/anonym/A.java +++ b/src/main/java/pr2/nestedclasses/basics/anonym/A.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.anonym; +package pr2.geschachtelte_klassen.basics.anonym; class A { diff --git a/src/main/java/pr2/nestedclasses/basics/anzahl/A.java b/src/main/java/pr2/nestedclasses/basics/anzahl/A.java index a4be4c9..a1f0e28 100644 --- a/src/main/java/pr2/nestedclasses/basics/anzahl/A.java +++ b/src/main/java/pr2/nestedclasses/basics/anzahl/A.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.anzahl; +package pr2.geschachtelte_klassen.basics.anzahl; public class A { class B { } diff --git a/src/main/java/pr2/nestedclasses/basics/arten/A.java b/src/main/java/pr2/nestedclasses/basics/arten/A.java index 942986b..57f0745 100644 --- a/src/main/java/pr2/nestedclasses/basics/arten/A.java +++ b/src/main/java/pr2/nestedclasses/basics/arten/A.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.arten; +package pr2.geschachtelte_klassen.basics.arten; class A { abstract class B { } diff --git a/src/main/java/pr2/nestedclasses/basics/local/A.java b/src/main/java/pr2/nestedclasses/basics/local/A.java index 6af66e7..2986d17 100644 --- a/src/main/java/pr2/nestedclasses/basics/local/A.java +++ b/src/main/java/pr2/nestedclasses/basics/local/A.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.local; +package pr2.geschachtelte_klassen.basics.local; class A { void methode() { diff --git a/src/main/java/pr2/nestedclasses/basics/priv/A.java b/src/main/java/pr2/nestedclasses/basics/priv/A.java index ab58450..054f182 100644 --- a/src/main/java/pr2/nestedclasses/basics/priv/A.java +++ b/src/main/java/pr2/nestedclasses/basics/priv/A.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.priv; +package pr2.geschachtelte_klassen.basics.priv; class A { diff --git a/src/main/java/pr2/nestedclasses/basics/priv/C.java b/src/main/java/pr2/nestedclasses/basics/priv/C.java index bdf73d1..97320c4 100644 --- a/src/main/java/pr2/nestedclasses/basics/priv/C.java +++ b/src/main/java/pr2/nestedclasses/basics/priv/C.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.priv; +package pr2.geschachtelte_klassen.basics.priv; class C { diff --git a/src/main/java/pr2/nestedclasses/basics/sichtbarkeit/A.java b/src/main/java/pr2/nestedclasses/basics/sichtbarkeit/A.java index 6ac1195..98f65f5 100644 --- a/src/main/java/pr2/nestedclasses/basics/sichtbarkeit/A.java +++ b/src/main/java/pr2/nestedclasses/basics/sichtbarkeit/A.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.sichtbarkeit; +package pr2.geschachtelte_klassen.basics.sichtbarkeit; class A { private class B { } diff --git a/src/main/java/pr2/nestedclasses/basics/tiefe/A.java b/src/main/java/pr2/nestedclasses/basics/tiefe/A.java index a2f6feb..4e5ae15 100644 --- a/src/main/java/pr2/nestedclasses/basics/tiefe/A.java +++ b/src/main/java/pr2/nestedclasses/basics/tiefe/A.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.tiefe; +package pr2.geschachtelte_klassen.basics.tiefe; class A { class B { diff --git a/src/main/java/pr2/nestedclasses/basics/vererbung/A.java b/src/main/java/pr2/nestedclasses/basics/vererbung/A.java index e487608..fb0eda1 100644 --- a/src/main/java/pr2/nestedclasses/basics/vererbung/A.java +++ b/src/main/java/pr2/nestedclasses/basics/vererbung/A.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.vererbung; +package pr2.geschachtelte_klassen.basics.vererbung; import java.io.Serializable; import java.util.ArrayList; diff --git a/src/main/java/pr2/nestedclasses/basics/vererbunginnen/A.java b/src/main/java/pr2/nestedclasses/basics/vererbunginnen/A.java index 95eefd8..85639ed 100644 --- a/src/main/java/pr2/nestedclasses/basics/vererbunginnen/A.java +++ b/src/main/java/pr2/nestedclasses/basics/vererbunginnen/A.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.basics.vererbunginnen; +package pr2.geschachtelte_klassen.basics.vererbunginnen; public class A { class B extends A { } diff --git a/src/main/java/pr2/nestedclasses/callback/Berechnung.java b/src/main/java/pr2/nestedclasses/callback/Berechnung.java index 1385bb3..741aaa4 100644 --- a/src/main/java/pr2/nestedclasses/callback/Berechnung.java +++ b/src/main/java/pr2/nestedclasses/callback/Berechnung.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.callback; +package pr2.geschachtelte_klassen.callback; public class Berechnung { diff --git a/src/main/java/pr2/nestedclasses/callback/Funktion.java b/src/main/java/pr2/nestedclasses/callback/Funktion.java index fc748a2..dcd8d06 100644 --- a/src/main/java/pr2/nestedclasses/callback/Funktion.java +++ b/src/main/java/pr2/nestedclasses/callback/Funktion.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.callback; +package pr2.geschachtelte_klassen.callback; public interface Funktion { public abstract int apply(int o1, int o2); diff --git a/src/main/java/pr2/nestedclasses/callback/TestBerechnung.java b/src/main/java/pr2/nestedclasses/callback/TestBerechnung.java index 7ebbb6f..d63ad75 100644 --- a/src/main/java/pr2/nestedclasses/callback/TestBerechnung.java +++ b/src/main/java/pr2/nestedclasses/callback/TestBerechnung.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.callback; +package pr2.geschachtelte_klassen.callback; public class TestBerechnung { diff --git a/src/main/java/pr2/nestedclasses/decompiled/A$B.java b/src/main/java/pr2/nestedclasses/decompiled/A$B.java index 42a328c..09f8bff 100644 --- a/src/main/java/pr2/nestedclasses/decompiled/A$B.java +++ b/src/main/java/pr2/nestedclasses/decompiled/A$B.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.decompiled; +package pr2.geschachtelte_klassen.decompiled; public class A$B { private int i; diff --git a/src/main/java/pr2/nestedclasses/decompiled/A.java b/src/main/java/pr2/nestedclasses/decompiled/A.java index 03fca08..c22145f 100644 --- a/src/main/java/pr2/nestedclasses/decompiled/A.java +++ b/src/main/java/pr2/nestedclasses/decompiled/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.decompiled; +package pr2.geschachtelte_klassen.decompiled; public class A { diff --git a/src/main/java/pr2/nestedclasses/lambda/Aktion.java b/src/main/java/pr2/nestedclasses/lambda/Aktion.java index 63ff24c..a38f280 100644 --- a/src/main/java/pr2/nestedclasses/lambda/Aktion.java +++ b/src/main/java/pr2/nestedclasses/lambda/Aktion.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda; +package pr2.geschachtelte_klassen.lambda; @FunctionalInterface public interface Aktion { diff --git a/src/main/java/pr2/nestedclasses/lambda/Berechnung.java b/src/main/java/pr2/nestedclasses/lambda/Berechnung.java index a07c202..36aad1f 100644 --- a/src/main/java/pr2/nestedclasses/lambda/Berechnung.java +++ b/src/main/java/pr2/nestedclasses/lambda/Berechnung.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.lambda; +package pr2.geschachtelte_klassen.lambda; public class Berechnung { diff --git a/src/main/java/pr2/nestedclasses/lambda/Capture.java b/src/main/java/pr2/nestedclasses/lambda/Capture.java index 00068e7..9bd49ae 100644 --- a/src/main/java/pr2/nestedclasses/lambda/Capture.java +++ b/src/main/java/pr2/nestedclasses/lambda/Capture.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda; +package pr2.geschachtelte_klassen.lambda; import java.util.Arrays; import java.util.Comparator; diff --git a/src/main/java/pr2/nestedclasses/lambda/ComparatorFactory.java b/src/main/java/pr2/nestedclasses/lambda/ComparatorFactory.java index 3e89262..f64a315 100644 --- a/src/main/java/pr2/nestedclasses/lambda/ComparatorFactory.java +++ b/src/main/java/pr2/nestedclasses/lambda/ComparatorFactory.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda; +package pr2.geschachtelte_klassen.lambda; import java.util.Comparator; diff --git a/src/main/java/pr2/nestedclasses/lambda/Funktion.java b/src/main/java/pr2/nestedclasses/lambda/Funktion.java index 93e0e37..7ddf366 100644 --- a/src/main/java/pr2/nestedclasses/lambda/Funktion.java +++ b/src/main/java/pr2/nestedclasses/lambda/Funktion.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda; +package pr2.geschachtelte_klassen.lambda; public interface Funktion { public int apply(int a, int b); diff --git a/src/main/java/pr2/nestedclasses/lambda/Rechner.java b/src/main/java/pr2/nestedclasses/lambda/Rechner.java index 76c9de9..4655df1 100644 --- a/src/main/java/pr2/nestedclasses/lambda/Rechner.java +++ b/src/main/java/pr2/nestedclasses/lambda/Rechner.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda; +package pr2.geschachtelte_klassen.lambda; public class Rechner { diff --git a/src/main/java/pr2/nestedclasses/lambda/RechnerLambda.java b/src/main/java/pr2/nestedclasses/lambda/RechnerLambda.java index f371e03..fe3865a 100644 --- a/src/main/java/pr2/nestedclasses/lambda/RechnerLambda.java +++ b/src/main/java/pr2/nestedclasses/lambda/RechnerLambda.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda; +package pr2.geschachtelte_klassen.lambda; public class RechnerLambda { public static void main(String[] args) { diff --git a/src/main/java/pr2/nestedclasses/lambda/Scoping.java b/src/main/java/pr2/nestedclasses/lambda/Scoping.java index 137e943..94e14a3 100644 --- a/src/main/java/pr2/nestedclasses/lambda/Scoping.java +++ b/src/main/java/pr2/nestedclasses/lambda/Scoping.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda; +package pr2.geschachtelte_klassen.lambda; public class Scoping { diff --git a/src/main/java/pr2/nestedclasses/lambda/Scoping2.java b/src/main/java/pr2/nestedclasses/lambda/Scoping2.java index 749cc35..9867aa8 100644 --- a/src/main/java/pr2/nestedclasses/lambda/Scoping2.java +++ b/src/main/java/pr2/nestedclasses/lambda/Scoping2.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda; +package pr2.geschachtelte_klassen.lambda; public class Scoping2 { diff --git a/src/main/java/pr2/nestedclasses/lambda/function/Rechner.java b/src/main/java/pr2/nestedclasses/lambda/function/Rechner.java index 200f5a1..4e93484 100644 --- a/src/main/java/pr2/nestedclasses/lambda/function/Rechner.java +++ b/src/main/java/pr2/nestedclasses/lambda/function/Rechner.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda.function; +package pr2.geschachtelte_klassen.lambda.function; import java.util.function.IntBinaryOperator; diff --git a/src/main/java/pr2/nestedclasses/lambda/function/RechnerKurz.java b/src/main/java/pr2/nestedclasses/lambda/function/RechnerKurz.java index 9fb4b59..2eae946 100644 --- a/src/main/java/pr2/nestedclasses/lambda/function/RechnerKurz.java +++ b/src/main/java/pr2/nestedclasses/lambda/function/RechnerKurz.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda.function; +package pr2.geschachtelte_klassen.lambda.function; import java.util.function.IntBinaryOperator; diff --git a/src/main/java/pr2/nestedclasses/lambda/methodref/Funktion.java b/src/main/java/pr2/nestedclasses/lambda/methodref/Funktion.java index 54d403a..8df0176 100644 --- a/src/main/java/pr2/nestedclasses/lambda/methodref/Funktion.java +++ b/src/main/java/pr2/nestedclasses/lambda/methodref/Funktion.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda.methodref; +package pr2.geschachtelte_klassen.lambda.methodref; public interface Funktion { public int apply(int a, int b); diff --git a/src/main/java/pr2/nestedclasses/lambda/methodref/Funktionssammlung.java b/src/main/java/pr2/nestedclasses/lambda/methodref/Funktionssammlung.java index e49adf9..d42ed76 100644 --- a/src/main/java/pr2/nestedclasses/lambda/methodref/Funktionssammlung.java +++ b/src/main/java/pr2/nestedclasses/lambda/methodref/Funktionssammlung.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda.methodref; +package pr2.geschachtelte_klassen.lambda.methodref; public class Funktionssammlung { diff --git a/src/main/java/pr2/nestedclasses/lambda/methodref/Main.java b/src/main/java/pr2/nestedclasses/lambda/methodref/Main.java index 987f353..7665741 100644 --- a/src/main/java/pr2/nestedclasses/lambda/methodref/Main.java +++ b/src/main/java/pr2/nestedclasses/lambda/methodref/Main.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.lambda.methodref; +package pr2.geschachtelte_klassen.lambda.methodref; public class Main { public static void main(String[] args) { diff --git a/src/main/java/pr2/nestedclasses/lambda/typing/Caller.java b/src/main/java/pr2/nestedclasses/lambda/typing/Caller.java index 0864a6c..8960405 100644 --- a/src/main/java/pr2/nestedclasses/lambda/typing/Caller.java +++ b/src/main/java/pr2/nestedclasses/lambda/typing/Caller.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.lambda.typing; +package pr2.geschachtelte_klassen.lambda.typing; public interface Caller { public int call(); diff --git a/src/main/java/pr2/nestedclasses/lambda/typing/Runner.java b/src/main/java/pr2/nestedclasses/lambda/typing/Runner.java index 886c9d6..852404b 100644 --- a/src/main/java/pr2/nestedclasses/lambda/typing/Runner.java +++ b/src/main/java/pr2/nestedclasses/lambda/typing/Runner.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.lambda.typing; +package pr2.geschachtelte_klassen.lambda.typing; public interface Runner { public void run(); diff --git a/src/main/java/pr2/nestedclasses/lambda/typing/TargetTyping.java b/src/main/java/pr2/nestedclasses/lambda/typing/TargetTyping.java index 2c70869..5774efa 100644 --- a/src/main/java/pr2/nestedclasses/lambda/typing/TargetTyping.java +++ b/src/main/java/pr2/nestedclasses/lambda/typing/TargetTyping.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.lambda.typing; +package pr2.geschachtelte_klassen.lambda.typing; public class TargetTyping { public void doIt(Runner r) { diff --git a/src/main/java/pr2/nestedclasses/local/Escape.java b/src/main/java/pr2/nestedclasses/local/Escape.java index b4cfb63..98f1bee 100644 --- a/src/main/java/pr2/nestedclasses/local/Escape.java +++ b/src/main/java/pr2/nestedclasses/local/Escape.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.local; +package pr2.geschachtelte_klassen.local; public class Escape { diff --git a/src/main/java/pr2/nestedclasses/local/LocalBeispiel.java b/src/main/java/pr2/nestedclasses/local/LocalBeispiel.java index 8cf2c1a..c7d2064 100644 --- a/src/main/java/pr2/nestedclasses/local/LocalBeispiel.java +++ b/src/main/java/pr2/nestedclasses/local/LocalBeispiel.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.local; +package pr2.geschachtelte_klassen.local; public class LocalBeispiel { diff --git a/src/main/java/pr2/nestedclasses/local/LocalMitVariable.java b/src/main/java/pr2/nestedclasses/local/LocalMitVariable.java index f826ef4..f1a368f 100644 --- a/src/main/java/pr2/nestedclasses/local/LocalMitVariable.java +++ b/src/main/java/pr2/nestedclasses/local/LocalMitVariable.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.local; +package pr2.geschachtelte_klassen.local; public class LocalMitVariable { diff --git a/src/main/java/pr2/nestedclasses/local/LocalMitVariableUndInstanz.java b/src/main/java/pr2/nestedclasses/local/LocalMitVariableUndInstanz.java index cce2a67..24e4ba6 100644 --- a/src/main/java/pr2/nestedclasses/local/LocalMitVariableUndInstanz.java +++ b/src/main/java/pr2/nestedclasses/local/LocalMitVariableUndInstanz.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.local; +package pr2.geschachtelte_klassen.local; public class LocalMitVariableUndInstanz { diff --git a/src/main/java/pr2/nestedclasses/local/Outer.java b/src/main/java/pr2/nestedclasses/local/Outer.java index 5a46e9a..a119f14 100644 --- a/src/main/java/pr2/nestedclasses/local/Outer.java +++ b/src/main/java/pr2/nestedclasses/local/Outer.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.local; +package pr2.geschachtelte_klassen.local; public class Outer { diff --git a/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer.java b/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer.java index 6330b78..bc8becd 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.nonstatic.computer; +package pr2.geschachtelte_klassen.nonstatic.computer; public class Computer { diff --git a/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer2.java b/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer2.java index 6c5356f..90ed00d 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer2.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer2.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.nonstatic.computer; +package pr2.geschachtelte_klassen.nonstatic.computer; public class Computer2 { diff --git a/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer3.java b/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer3.java index b86d190..e43ff35 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer3.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer3.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.nonstatic.computer; +package pr2.geschachtelte_klassen.nonstatic.computer; public class Computer3 { diff --git a/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer4.java b/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer4.java index f5373ae..cfb803f 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer4.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/computer/Computer4.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.nonstatic.computer; +package pr2.geschachtelte_klassen.nonstatic.computer; public class Computer4 { diff --git a/src/main/java/pr2/nestedclasses/nonstatic/computer/Outer.java b/src/main/java/pr2/nestedclasses/nonstatic/computer/Outer.java index 915a3a1..8914b43 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/computer/Outer.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/computer/Outer.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.nonstatic.computer; +package pr2.geschachtelte_klassen.nonstatic.computer; public class Outer { class Inner { } diff --git a/src/main/java/pr2/nestedclasses/nonstatic/v1/Outer.java b/src/main/java/pr2/nestedclasses/nonstatic/v1/Outer.java index 3afa43e..aaa22f5 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/v1/Outer.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/v1/Outer.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.nonstatic.v1; +package pr2.geschachtelte_klassen.nonstatic.v1; public class Outer { diff --git a/src/main/java/pr2/nestedclasses/nonstatic/v1/UseOuter.java b/src/main/java/pr2/nestedclasses/nonstatic/v1/UseOuter.java index c7949ff..ccb9493 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/v1/UseOuter.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/v1/UseOuter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.nonstatic.v1; +package pr2.geschachtelte_klassen.nonstatic.v1; public class UseOuter { diff --git a/src/main/java/pr2/nestedclasses/nonstatic/v2/Outer.java b/src/main/java/pr2/nestedclasses/nonstatic/v2/Outer.java index fb5c20f..e24c360 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/v2/Outer.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/v2/Outer.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.nonstatic.v2; +package pr2.geschachtelte_klassen.nonstatic.v2; public class Outer { diff --git a/src/main/java/pr2/nestedclasses/nonstatic/v2/UseOuter.java b/src/main/java/pr2/nestedclasses/nonstatic/v2/UseOuter.java index 16183de..fd903f8 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/v2/UseOuter.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/v2/UseOuter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.nonstatic.v2; +package pr2.geschachtelte_klassen.nonstatic.v2; public class UseOuter { diff --git a/src/main/java/pr2/nestedclasses/nonstatic/v3/A.java b/src/main/java/pr2/nestedclasses/nonstatic/v3/A.java index c7ce8c4..b654492 100644 --- a/src/main/java/pr2/nestedclasses/nonstatic/v3/A.java +++ b/src/main/java/pr2/nestedclasses/nonstatic/v3/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.nonstatic.v3; +package pr2.geschachtelte_klassen.nonstatic.v3; public class A { diff --git a/src/main/java/pr2/nestedclasses/quiz/Outer.java b/src/main/java/pr2/nestedclasses/quiz/Outer.java index 6358285..82bb111 100644 --- a/src/main/java/pr2/nestedclasses/quiz/Outer.java +++ b/src/main/java/pr2/nestedclasses/quiz/Outer.java @@ -1,4 +1,4 @@ -package pr2.nestedclasses.quiz; +package pr2.geschachtelte_klassen.quiz; public class Outer { public class Inner1 extends Outer {} diff --git a/src/main/java/pr2/nestedclasses/quiz/Twister.java b/src/main/java/pr2/nestedclasses/quiz/Twister.java index ad7bf26..113c1ba 100644 --- a/src/main/java/pr2/nestedclasses/quiz/Twister.java +++ b/src/main/java/pr2/nestedclasses/quiz/Twister.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.quiz; +package pr2.geschachtelte_klassen.quiz; public class Twister { diff --git a/src/main/java/pr2/nestedclasses/statisch/v1/Outer.java b/src/main/java/pr2/nestedclasses/statisch/v1/Outer.java index 91a0a4e..5c70e00 100644 --- a/src/main/java/pr2/nestedclasses/statisch/v1/Outer.java +++ b/src/main/java/pr2/nestedclasses/statisch/v1/Outer.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.statisch.v1; +package pr2.geschachtelte_klassen.statisch.v1; public class Outer { static class Inner { } diff --git a/src/main/java/pr2/nestedclasses/statisch/v1/StaticMember.java b/src/main/java/pr2/nestedclasses/statisch/v1/StaticMember.java index 6d9af04..41e400f 100644 --- a/src/main/java/pr2/nestedclasses/statisch/v1/StaticMember.java +++ b/src/main/java/pr2/nestedclasses/statisch/v1/StaticMember.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.statisch.v1; +package pr2.geschachtelte_klassen.statisch.v1; public class StaticMember { diff --git a/src/main/java/pr2/nestedclasses/statisch/v2/Outer.java b/src/main/java/pr2/nestedclasses/statisch/v2/Outer.java index 6f1313c..01060af 100644 --- a/src/main/java/pr2/nestedclasses/statisch/v2/Outer.java +++ b/src/main/java/pr2/nestedclasses/statisch/v2/Outer.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.statisch.v2; +package pr2.geschachtelte_klassen.statisch.v2; public class Outer { diff --git a/src/main/java/pr2/nestedclasses/statisch/v2/PrivaterZugriff.java b/src/main/java/pr2/nestedclasses/statisch/v2/PrivaterZugriff.java index f7b4661..994d984 100644 --- a/src/main/java/pr2/nestedclasses/statisch/v2/PrivaterZugriff.java +++ b/src/main/java/pr2/nestedclasses/statisch/v2/PrivaterZugriff.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.nestedclasses.statisch.v2; +package pr2.geschachtelte_klassen.statisch.v2; public class PrivaterZugriff { diff --git a/src/main/java/pr2/nestedclasses/statisch/v2/UseOuter.java b/src/main/java/pr2/nestedclasses/statisch/v2/UseOuter.java index 8286e8d..a2350a9 100644 --- a/src/main/java/pr2/nestedclasses/statisch/v2/UseOuter.java +++ b/src/main/java/pr2/nestedclasses/statisch/v2/UseOuter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.statisch.v2; +package pr2.geschachtelte_klassen.statisch.v2; public class UseOuter { diff --git a/src/main/java/pr2/nestedclasses/statisch/v2/Zugriff.java b/src/main/java/pr2/nestedclasses/statisch/v2/Zugriff.java index ed51110..e3e7513 100644 --- a/src/main/java/pr2/nestedclasses/statisch/v2/Zugriff.java +++ b/src/main/java/pr2/nestedclasses/statisch/v2/Zugriff.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.statisch.v2; +package pr2.geschachtelte_klassen.statisch.v2; public class Zugriff { diff --git a/src/main/java/pr2/nestedclasses/vererbung/Outer.java b/src/main/java/pr2/nestedclasses/vererbung/Outer.java index 2879417..e015f62 100644 --- a/src/main/java/pr2/nestedclasses/vererbung/Outer.java +++ b/src/main/java/pr2/nestedclasses/vererbung/Outer.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.nestedclasses.vererbung; +package pr2.geschachtelte_klassen.vererbung; public class Outer { diff --git a/src/main/java/pr2/oo/abstrakt/v1/Ente.java b/src/main/java/pr2/oo/abstrakt/v1/Ente.java new file mode 100644 index 0000000..c541584 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v1/Ente.java @@ -0,0 +1,10 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v1; + +public class Ente extends Tier { + + public void schwimmen() { + // mit den Füßen paddeln und mit Flügeln schlagen + // und überhaupt tolle Ente + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v1/Hund.java b/src/main/java/pr2/oo/abstrakt/v1/Hund.java new file mode 100644 index 0000000..faaa711 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v1/Hund.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v1; + +public class Hund extends Tier { + + public void bellen() { + // Maul auf und los + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v1/Tier.java b/src/main/java/pr2/oo/abstrakt/v1/Tier.java new file mode 100644 index 0000000..5b1c0a8 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v1/Tier.java @@ -0,0 +1,11 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v1; + +public class Tier { + + private int alter; + + public void fortbewegen() { /* mhmm... Tiere bewegen sich, aber wie? */ } + + public void fressen() { /* mhmm... Tiere fressen, aber wie? */ } +} diff --git a/src/main/java/pr2/oo/abstrakt/v1/Verwender.java b/src/main/java/pr2/oo/abstrakt/v1/Verwender.java new file mode 100644 index 0000000..f9e398d --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v1/Verwender.java @@ -0,0 +1,15 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v1; + +public class Verwender { + + public static void main(String[] args) { + Hund h = new Hund(); + h.fortbewegen(); + + Tier t = new Tier(); + + Tier e = new Ente(); + e.fressen(); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v10/A.java b/src/main/java/pr2/oo/abstrakt/v10/A.java new file mode 100644 index 0000000..f24e19c --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v10/A.java @@ -0,0 +1,13 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v10; + +public abstract class A { + + public abstract void abstrakt1(); + + public abstract void abstrakt2(); + + public void konkret() { + System.out.println("Konkret Alter!"); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v10/B.java b/src/main/java/pr2/oo/abstrakt/v10/B.java new file mode 100644 index 0000000..3756ff0 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v10/B.java @@ -0,0 +1,15 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v10; + +public class B extends A { + + @Override + public void abstrakt1() { + System.out.println("Abstrakt 1 aus B"); + } + + @Override + public void abstrakt2() { + System.out.println("Abstrakt 2 aus B"); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v10/C.java b/src/main/java/pr2/oo/abstrakt/v10/C.java new file mode 100644 index 0000000..92f76b2 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v10/C.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v10; + +public abstract class C extends A { + + public void abstrakt1() { + System.out.println("Abstrakt 1 aus C"); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v10/D.java b/src/main/java/pr2/oo/abstrakt/v10/D.java new file mode 100644 index 0000000..f8aa187 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v10/D.java @@ -0,0 +1,4 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v10; + +public abstract class D extends C { /* empty */ } diff --git a/src/main/java/pr2/oo/abstrakt/v10/E.java b/src/main/java/pr2/oo/abstrakt/v10/E.java new file mode 100644 index 0000000..1dcb2d6 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v10/E.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v10; + +public class E extends D { + + public void abstrakt2() { + System.out.println("Abstrakt 2 aus E"); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v10/F.java b/src/main/java/pr2/oo/abstrakt/v10/F.java new file mode 100644 index 0000000..21d1650 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v10/F.java @@ -0,0 +1,4 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v10; + +public abstract class F extends A { /* empty */ } diff --git a/src/main/java/pr2/oo/abstrakt/v10/G.java b/src/main/java/pr2/oo/abstrakt/v10/G.java new file mode 100644 index 0000000..270f6ad --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v10/G.java @@ -0,0 +1,13 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v10; + +public class G extends F { + + public void abstrakt1() { + System.out.println("Abstrakt 1 aus G"); + } + + public void abstrakt2() { + System.out.println("Abstrakt 2 aus G"); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v10/Verwender.java b/src/main/java/pr2/oo/abstrakt/v10/Verwender.java new file mode 100644 index 0000000..9f68fdc --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v10/Verwender.java @@ -0,0 +1,22 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v10; + +public class Verwender { + + public static void main(String[] args) { + A b = new B(); + + b.konkret(); + b.abstrakt1(); + b.abstrakt2(); + + A d = new E(); + d.konkret(); + d.abstrakt1(); + d.abstrakt2(); + + A g = new G(); g.konkret(); g.abstrakt1(); g.abstrakt2(); + + + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v11/A.java b/src/main/java/pr2/oo/abstrakt/v11/A.java new file mode 100644 index 0000000..0ba1007 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v11/A.java @@ -0,0 +1,13 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v11; + +public abstract class A { + + public abstract void abstrakt1(); + + public abstract void abstrakt2(); + + public void konkret() { + System.out.println("Konkret Alter!"); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v11/B.java b/src/main/java/pr2/oo/abstrakt/v11/B.java new file mode 100644 index 0000000..b20ce37 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v11/B.java @@ -0,0 +1,16 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v11; + +public abstract class B extends A { + + @Override + public void abstrakt1() { + System.out.println("Abstrakt 1 aus B"); + } + + public abstract void abstrakt3(); + + public void konkret2() { + System.out.println("Konkret 2 aus B"); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v11/C.java b/src/main/java/pr2/oo/abstrakt/v11/C.java new file mode 100644 index 0000000..55a8f72 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v11/C.java @@ -0,0 +1,15 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v11; + +public class C extends B { + + @Override + public void abstrakt2() { + System.out.println("Abstrakt 2 aus C"); + } + + @Override + public void abstrakt3() { + System.out.println("Abstrakt 3 aus C"); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v11/D.java b/src/main/java/pr2/oo/abstrakt/v11/D.java new file mode 100644 index 0000000..f15320c --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v11/D.java @@ -0,0 +1,10 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v11; + +public class D extends C { + + @Override + public void abstrakt1() { + System.out.println("Abstrakt 1 aus D"); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v2/Ente.java b/src/main/java/pr2/oo/abstrakt/v2/Ente.java new file mode 100644 index 0000000..2d13462 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v2/Ente.java @@ -0,0 +1,11 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v2; + +public class Ente extends Tier { + + public void schwimmen() { /* mit den Füßen paddeln */ } + + public void fortbewegen() { /* watscheln */ } + + public void fressen() { /* abtauchen und Schnabel auf */ } +} diff --git a/src/main/java/pr2/oo/abstrakt/v2/Hund.java b/src/main/java/pr2/oo/abstrakt/v2/Hund.java new file mode 100644 index 0000000..ed4c0d9 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v2/Hund.java @@ -0,0 +1,11 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v2; + +public class Hund extends Tier { + + public void bellen() { /* Maul auf und los */ } + + public void fortbewegen() { /* auf allen Vieren dackeln */ } + + public void fressen() { /* Maul auf und runter mit dem Futter */ } +} diff --git a/src/main/java/pr2/oo/abstrakt/v2/Tier.java b/src/main/java/pr2/oo/abstrakt/v2/Tier.java new file mode 100644 index 0000000..d33c5de --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v2/Tier.java @@ -0,0 +1,6 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v2; + +public class Tier { + private int alter; +} diff --git a/src/main/java/pr2/oo/abstrakt/v2/Verwender.java b/src/main/java/pr2/oo/abstrakt/v2/Verwender.java new file mode 100644 index 0000000..7d679ad --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v2/Verwender.java @@ -0,0 +1,23 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v2; + +public class Verwender { + + public void main(String[] args) { + Hund h = new Hund(); + füttern(h); + + Ente e = new Ente(); + füttern(e); + } + + public void füttern(Tier t) { + + if (t instanceof Hund) { + ((Hund) t).fressen(); + } + else if (t instanceof Ente) { + ((Ente) t).fressen(); + } + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v3/Ente.java b/src/main/java/pr2/oo/abstrakt/v3/Ente.java new file mode 100644 index 0000000..8545eae --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v3/Ente.java @@ -0,0 +1,10 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v3; + +public class Ente extends Tier { + + public void schwimmen() { /* mit den Füßen paddeln */ } + + @Override + public void fortbewegen() { /* watscheln */ } +} diff --git a/src/main/java/pr2/oo/abstrakt/v3/Hund.java b/src/main/java/pr2/oo/abstrakt/v3/Hund.java new file mode 100644 index 0000000..7d6d232 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v3/Hund.java @@ -0,0 +1,13 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v3; + +public class Hund extends Tier { + + public void bellen() { /* Maul auf und los */ } + + @Override + public void fortbewegen() { /* auf allen Vieren dackeln */ } + + @Override + public void fressen() { /* Maul auf und runter mit dem Futter */ } +} diff --git a/src/main/java/pr2/oo/abstrakt/v3/Tier.java b/src/main/java/pr2/oo/abstrakt/v3/Tier.java new file mode 100644 index 0000000..928de38 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v3/Tier.java @@ -0,0 +1,10 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v3; + +public class Tier { + private int alter; + + public void fortbewegen() { /* mhmm... Tiere bewegen sich, aber wie? */ } + + public void fressen() { /* mhmm... Tiere fressen, aber wie? */ } +} diff --git a/src/main/java/pr2/oo/abstrakt/v3/Verwender.java b/src/main/java/pr2/oo/abstrakt/v3/Verwender.java new file mode 100644 index 0000000..9fc9cc3 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v3/Verwender.java @@ -0,0 +1,32 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v3; + +public class Verwender { + + public void main(String[] args) { + + { + Hund h = new Hund(); + h.fortbewegen(); + + Tier t = new Tier(); + + Tier e = new Ente(); + e.fressen(); + } + + { + Hund h = new Hund(); + füttern(h); + + Ente e = new Ente(); + füttern(e); + } + + } + + public void füttern(Tier t) { + // Futter bereitstellen + t.fressen(); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v4/Ente.java b/src/main/java/pr2/oo/abstrakt/v4/Ente.java new file mode 100644 index 0000000..ca715f6 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v4/Ente.java @@ -0,0 +1,13 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v4; + +public class Ente extends Tier { + + public void schwimmen() { /* mit den Füßen paddeln */ } + + @Override + public void fortbewegen() { /* watscheln */ } + + @Override + public void fressen() { /* abtauchen und Schnabel auf */ } +} diff --git a/src/main/java/pr2/oo/abstrakt/v4/Hund.java b/src/main/java/pr2/oo/abstrakt/v4/Hund.java new file mode 100644 index 0000000..246c637 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v4/Hund.java @@ -0,0 +1,13 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v4; + +public class Hund extends Tier { + + public void bellen() { /* Maul auf und los */ } + + @Override + public void fortbewegen() { /* auf allen Vieren dackeln */ } + + @Override + public void fressen() { /* Maul auf und runter mit dem Futter */ } +} diff --git a/src/main/java/pr2/oo/abstrakt/v4/Tier.java b/src/main/java/pr2/oo/abstrakt/v4/Tier.java new file mode 100644 index 0000000..d135c63 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v4/Tier.java @@ -0,0 +1,11 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v4; + +public abstract class Tier { + + private int alter; + + public abstract void fortbewegen(); + + public abstract void fressen(); +} diff --git a/src/main/java/pr2/oo/abstrakt/v4/Verwender.java b/src/main/java/pr2/oo/abstrakt/v4/Verwender.java new file mode 100644 index 0000000..58cfac4 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v4/Verwender.java @@ -0,0 +1,32 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v4; + +public class Verwender { + + public void main(String[] args) { + + { + Hund h = new Hund(); + h.fortbewegen(); + + // Tier t = new Tier(); + + Tier e = new Ente(); + e.fressen(); + } + + { + Hund h = new Hund(); + füttern(h); + + Ente e = new Ente(); + füttern(e); + } + + } + + public void füttern(Tier t) { + // Futter bereitstellen + t.fressen(); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v5/Angestellter.java b/src/main/java/pr2/oo/abstrakt/v5/Angestellter.java new file mode 100644 index 0000000..0a6f1df --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v5/Angestellter.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v5; + +public class Angestellter extends Mitarbeiter { + + private int monatsgehalt; + + public int berechneZahlung() { + return monatsgehalt; + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v5/Arbeiter.java b/src/main/java/pr2/oo/abstrakt/v5/Arbeiter.java new file mode 100644 index 0000000..06449fb --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v5/Arbeiter.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v5; + +public class Arbeiter extends Mitarbeiter { + + private int akkordlohn; + private int grundlohn; + private int akkordStueckzahl; + + public int berechneZahlung() { + return grundlohn + akkordlohn * akkordStueckzahl; + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v5/Lohnbuchhaltung.java b/src/main/java/pr2/oo/abstrakt/v5/Lohnbuchhaltung.java new file mode 100644 index 0000000..3f6e2e5 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v5/Lohnbuchhaltung.java @@ -0,0 +1,31 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v5; + +public class Lohnbuchhaltung { + + public void ueberweisung(Mitarbeiter[] mitarbeiter) { + + for (int i = 0; i < mitarbeiter.length; i++) { + Mitarbeiter m = mitarbeiter[i]; + + int zahlbetrag; + + if (m instanceof Arbeiter) { + Arbeiter a = (Arbeiter) m; + zahlbetrag = a.berechneZahlung(); + } + else if (m instanceof Angestellter) { + Angestellter a = (Angestellter) m; + zahlbetrag = a.berechneZahlung(); + } + else { + System.out.println("Fehler"); + } + + // Zahlung durchf�hren + + } + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v5/Mitarbeiter.java b/src/main/java/pr2/oo/abstrakt/v5/Mitarbeiter.java new file mode 100644 index 0000000..1cb47ab --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v5/Mitarbeiter.java @@ -0,0 +1,7 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v5; + +public class Mitarbeiter { +} diff --git a/src/main/java/pr2/oo/abstrakt/v5/Vorstand.java b/src/main/java/pr2/oo/abstrakt/v5/Vorstand.java new file mode 100644 index 0000000..771aca8 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v5/Vorstand.java @@ -0,0 +1,9 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v5; + +public class Vorstand extends Mitarbeiter { + private int monatsgehalt; + private int aktienoptionen; +} diff --git a/src/main/java/pr2/oo/abstrakt/v6/Angestellter.java b/src/main/java/pr2/oo/abstrakt/v6/Angestellter.java new file mode 100644 index 0000000..4e1b487 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v6/Angestellter.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v6; + +public class Angestellter extends Mitarbeiter { + + private int monatsgehalt; + + public int berechneZahlung() { + return monatsgehalt; + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v6/Arbeiter.java b/src/main/java/pr2/oo/abstrakt/v6/Arbeiter.java new file mode 100644 index 0000000..0bcb862 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v6/Arbeiter.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v6; + +public class Arbeiter extends Mitarbeiter { + + private int akkordlohn; + private int grundlohn; + private int akkordStueckzahl; + + public int berechneZahlung() { + return grundlohn + akkordlohn * akkordStueckzahl; + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v6/Lohnbuchhaltung.java b/src/main/java/pr2/oo/abstrakt/v6/Lohnbuchhaltung.java new file mode 100644 index 0000000..5cbd795 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v6/Lohnbuchhaltung.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v6; + +public class Lohnbuchhaltung { + + public void ueberweisung(Mitarbeiter[] mitarbeiter) { + + for (int i = 0; i < mitarbeiter.length; i++) { + int zahlbetrag = mitarbeiter[i].berechneZahlung(); + // Zahlung durchf�hren + } + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v6/Mitarbeiter.java b/src/main/java/pr2/oo/abstrakt/v6/Mitarbeiter.java new file mode 100644 index 0000000..0c119b1 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v6/Mitarbeiter.java @@ -0,0 +1,12 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v6; + +public class Mitarbeiter { + + public int berechneZahlung() { + System.out.println("Fehler..."); + return 0; + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v6/Vorstand.java b/src/main/java/pr2/oo/abstrakt/v6/Vorstand.java new file mode 100644 index 0000000..35c207d --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v6/Vorstand.java @@ -0,0 +1,9 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v6; + +public class Vorstand extends Mitarbeiter { + private int monatsgehalt; + private int aktienoptionen; +} diff --git a/src/main/java/pr2/oo/abstrakt/v7/Angestellter.java b/src/main/java/pr2/oo/abstrakt/v7/Angestellter.java new file mode 100644 index 0000000..293efb5 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v7/Angestellter.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v7; + +public class Angestellter extends Mitarbeiter { + + private int monatsgehalt; + + public int berechneZahlung() { + return monatsgehalt; + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v7/Arbeiter.java b/src/main/java/pr2/oo/abstrakt/v7/Arbeiter.java new file mode 100644 index 0000000..034628b --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v7/Arbeiter.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v7; + +public class Arbeiter extends Mitarbeiter { + + private int akkordlohn; + private int grundlohn; + private int akkordStueckzahl; + + public int berechneZahlung() { + return grundlohn + akkordlohn * akkordStueckzahl; + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v7/Lohnbuchhaltung.java b/src/main/java/pr2/oo/abstrakt/v7/Lohnbuchhaltung.java new file mode 100644 index 0000000..a22ae0c --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v7/Lohnbuchhaltung.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v7; + +public class Lohnbuchhaltung { + + public void ueberweisung(Mitarbeiter[] mitarbeiter) { + + for (int i = 0; i < mitarbeiter.length; i++) { + int zahlbetrag = mitarbeiter[i].berechneZahlung(); + // Zahlung durchführen + } + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v7/Mitarbeiter.java b/src/main/java/pr2/oo/abstrakt/v7/Mitarbeiter.java new file mode 100644 index 0000000..5b1a363 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v7/Mitarbeiter.java @@ -0,0 +1,9 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v7; + +public abstract class Mitarbeiter { + + protected abstract int berechneZahlung(); +} diff --git a/src/main/java/pr2/oo/abstrakt/v7/Vorstand.java b/src/main/java/pr2/oo/abstrakt/v7/Vorstand.java new file mode 100644 index 0000000..16eaf82 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v7/Vorstand.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v7; + +public abstract class Vorstand extends Mitarbeiter { + +} diff --git a/src/main/java/pr2/oo/abstrakt/v8/Angestellter.java b/src/main/java/pr2/oo/abstrakt/v8/Angestellter.java new file mode 100644 index 0000000..046573c --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v8/Angestellter.java @@ -0,0 +1,18 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v8; + +public class Angestellter extends Mitarbeiter { + + private double zielbonus = 1000.0; + private double zielerreichung = 0.98; + + public double zielbonus() { + return zielbonus; + } + + public double zielerreichung() { + return zielerreichung; + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v8/Main.java b/src/main/java/pr2/oo/abstrakt/v8/Main.java new file mode 100644 index 0000000..77ad2ad --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v8/Main.java @@ -0,0 +1,14 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v8; + +/** + * + * + * @author Thomas Smits + */ +public class Main { + public static void main(String[] args) { + Mitarbeiter m = new Vorstand(); + System.out.println(m.bonus()); + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v8/Mitarbeiter.java b/src/main/java/pr2/oo/abstrakt/v8/Mitarbeiter.java new file mode 100644 index 0000000..c1b8586 --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v8/Mitarbeiter.java @@ -0,0 +1,14 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v8; + +public abstract class Mitarbeiter { + + public final double bonus() { + return zielbonus() * zielerreichung(); + } + + public abstract double zielerreichung(); + public abstract double zielbonus(); +} diff --git a/src/main/java/pr2/oo/abstrakt/v8/Vorstand.java b/src/main/java/pr2/oo/abstrakt/v8/Vorstand.java new file mode 100644 index 0000000..34dfacb --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v8/Vorstand.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.abstrakt.v8; + +public class Vorstand extends Mitarbeiter { + + private double firmengewinn = 300000.0; + + public double zielbonus() { + return 0.5 * firmengewinn; + } + + public double zielerreichung() { + return 1.00; + } +} diff --git a/src/main/java/pr2/oo/abstrakt/v9/Mitarbeiter.java b/src/main/java/pr2/oo/abstrakt/v9/Mitarbeiter.java new file mode 100644 index 0000000..95782ce --- /dev/null +++ b/src/main/java/pr2/oo/abstrakt/v9/Mitarbeiter.java @@ -0,0 +1,23 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.abstrakt.v9; + +import java.util.Date; + +public abstract class Mitarbeiter { + + protected String name; + protected double gehalt; + protected Date geboren; + + public Mitarbeiter(String name, double gehalt, Date geboren) { + this.name = name; + this.gehalt = gehalt; + this.geboren = geboren; + } + + public Date getGeburtsdatum() { + return geboren; + } + + protected abstract int berechneZahlung(); +} diff --git a/src/main/java/pr2/oo/finale/blankfinal/Kunde.java b/src/main/java/pr2/oo/finale/blankfinal/Kunde.java new file mode 100644 index 0000000..8fc1af5 --- /dev/null +++ b/src/main/java/pr2/oo/finale/blankfinal/Kunde.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.blankfinal; + +public class Kunde { + + private final int kundenNummer; + + public Kunde(int kundenNummer) { + this.kundenNummer = kundenNummer; + } +} diff --git a/src/main/java/pr2/oo/finale/v1/DeadCodeElemination.java b/src/main/java/pr2/oo/finale/v1/DeadCodeElemination.java new file mode 100644 index 0000000..ed37bce --- /dev/null +++ b/src/main/java/pr2/oo/finale/v1/DeadCodeElemination.java @@ -0,0 +1,18 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v1; + +public class DeadCodeElemination { + + public static final boolean SCHALTER = false; + + public static void main(String[] args) { + if (SCHALTER) { + System.out.println("Schalter AN"); + } + else { + System.out.println("Schalter AUS"); + } + } +} diff --git a/src/main/java/pr2/oo/finale/v1/Konstanten.java b/src/main/java/pr2/oo/finale/v1/Konstanten.java new file mode 100644 index 0000000..30ab65e --- /dev/null +++ b/src/main/java/pr2/oo/finale/v1/Konstanten.java @@ -0,0 +1,14 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v1; + +public class Konstanten { + public static final double PI = 3.14159265; + + public static final double NA = 6.0221415E23; + + public static final String XML_HEADER = ""; + + public static final int[] primzahlen = { 2, 3, 5, 7, 11, 13, 17, 19 }; +} diff --git a/src/main/java/pr2/oo/finale/v1/NoDeadCodeElemination.java b/src/main/java/pr2/oo/finale/v1/NoDeadCodeElemination.java new file mode 100644 index 0000000..0790ef1 --- /dev/null +++ b/src/main/java/pr2/oo/finale/v1/NoDeadCodeElemination.java @@ -0,0 +1,18 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v1; + +public class NoDeadCodeElemination { + + public static boolean schalter = false; + + public static void main(String[] args) { + if (schalter) { + System.out.println("Schalter AN"); + } + else { + System.out.println("Schalter AUS"); + } + } +} diff --git a/src/main/java/pr2/oo/finale/v2/A.java b/src/main/java/pr2/oo/finale/v2/A.java new file mode 100644 index 0000000..3605fb8 --- /dev/null +++ b/src/main/java/pr2/oo/finale/v2/A.java @@ -0,0 +1,9 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v2; + +public class A { + public void methode() {} + public final void finalMethode() {} +} diff --git a/src/main/java/pr2/oo/finale/v2/B.java b/src/main/java/pr2/oo/finale/v2/B.java new file mode 100644 index 0000000..4210a45 --- /dev/null +++ b/src/main/java/pr2/oo/finale/v2/B.java @@ -0,0 +1,14 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v2; + +public class B extends A { + + @Override + public void methode() {} + /* + @Override + public void finalMethode() {} + */ +} diff --git a/src/main/java/pr2/oo/finale/v2/FinaleVariablen.java b/src/main/java/pr2/oo/finale/v2/FinaleVariablen.java new file mode 100644 index 0000000..52a6ffa --- /dev/null +++ b/src/main/java/pr2/oo/finale/v2/FinaleVariablen.java @@ -0,0 +1,37 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v2; + +public class FinaleVariablen { +/* + public void methode1(final int k) { + k++; + } + + public void methode2() { + final boolean b = true; + final String s; + + if (b) { + s = "TRUE"; + } + else { + s = "FALSE"; + } + + b = false; + s.toUpperCase(); + } +public static void main(String[] args) { + FinaleVariablen f = new FinaleVariablen(); + f.methode2(true); +} + public void methode3() { + final boolean b = true; + final String s; + + s = b ? "TRUE" : "FALSE"; + } + */ +} diff --git a/src/main/java/pr2/oo/finale/v2/Konstanten.java b/src/main/java/pr2/oo/finale/v2/Konstanten.java new file mode 100644 index 0000000..fb6d299 --- /dev/null +++ b/src/main/java/pr2/oo/finale/v2/Konstanten.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v2; + +public class Konstanten { + public static final int[] PRIMZAHLEN = { 2, 3, 5, 7, 11, 13, 17, 19 }; +} diff --git a/src/main/java/pr2/oo/finale/v2/Konstantenverwender.java b/src/main/java/pr2/oo/finale/v2/Konstantenverwender.java new file mode 100644 index 0000000..8566060 --- /dev/null +++ b/src/main/java/pr2/oo/finale/v2/Konstantenverwender.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v2; + +import java.util.Arrays; + +public class Konstantenverwender { + + public static void main(String[] args) { + System.out.println(Arrays.toString(Konstanten.PRIMZAHLEN)); + Konstanten.PRIMZAHLEN[2] = 8; + System.out.println(Arrays.toString(Konstanten.PRIMZAHLEN)); + } +} diff --git a/src/main/java/pr2/oo/finale/v3/A.java b/src/main/java/pr2/oo/finale/v3/A.java new file mode 100644 index 0000000..e557ada --- /dev/null +++ b/src/main/java/pr2/oo/finale/v3/A.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v3; + +public final class A { + +} diff --git a/src/main/java/pr2/oo/finale/v3/B.java b/src/main/java/pr2/oo/finale/v3/B.java new file mode 100644 index 0000000..f68ad96 --- /dev/null +++ b/src/main/java/pr2/oo/finale/v3/B.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.finale.v3; + +public class B /* extends A */ { + +} diff --git a/src/main/java/pr2/oo/interfaces/callback/Addition.java b/src/main/java/pr2/oo/interfaces/callback/Addition.java new file mode 100644 index 0000000..daf73a2 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/callback/Addition.java @@ -0,0 +1,11 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.callback; + +public class Addition implements Funktion { + + public int apply(int o1, int o2) { + return o1 + o2; + } +} diff --git a/src/main/java/pr2/oo/interfaces/callback/Berechnung.java b/src/main/java/pr2/oo/interfaces/callback/Berechnung.java new file mode 100644 index 0000000..3c513c1 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/callback/Berechnung.java @@ -0,0 +1,20 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.callback; + +public class Berechnung { + + public static int berechne(int input1, int input2, Funktion funktion) { + int ergebnis = funktion.apply(input1, input2); + return ergebnis; + } + + public static void main(String[] args) { + Funktion sub = new Subtraktion(); + Funktion add = new Addition(); + + System.out.println(berechne(5, 3, sub)); + System.out.println(berechne(1, 7, add)); + } +} diff --git a/src/main/java/pr2/oo/interfaces/callback/Funktion.java b/src/main/java/pr2/oo/interfaces/callback/Funktion.java new file mode 100644 index 0000000..b8d8370 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/callback/Funktion.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.callback; + +public interface Funktion { + public abstract int apply(int o1, int o2); +} diff --git a/src/main/java/pr2/oo/interfaces/callback/Subtraktion.java b/src/main/java/pr2/oo/interfaces/callback/Subtraktion.java new file mode 100644 index 0000000..4240efb --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/callback/Subtraktion.java @@ -0,0 +1,11 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.callback; + +public class Subtraktion implements Funktion { + + public int apply(int o1, int o2) { + return o1 - o2; + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/ExtFlieger.java b/src/main/java/pr2/oo/interfaces/java8/ExtFlieger.java new file mode 100644 index 0000000..bb5ba07 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/ExtFlieger.java @@ -0,0 +1,17 @@ +package pr2.oo.interfaces.java8; + +public interface ExtFlieger extends Flieger { + + @Override + public default void steigen() { + // ersetzt die steigen Methode aus Flieger + System.out.println("Schnell steigen"); + } + + public void sinken(); // Methode ist jetzt abstrakt + + public default void starten() { + // Methode ist jetzt nicht mehr abstrakt + System.out.println("Kommt"); + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/Flieger.java b/src/main/java/pr2/oo/interfaces/java8/Flieger.java new file mode 100644 index 0000000..1f2c50b --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/Flieger.java @@ -0,0 +1,12 @@ +package pr2.oo.interfaces.java8; + +public interface Flieger { + public void starten(); + public void landen(); + public default void sinken() { + System.out.println("sinke"); + } + public default void steigen() { + System.out.println("steige"); + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/Flugzeug.java b/src/main/java/pr2/oo/interfaces/java8/Flugzeug.java new file mode 100644 index 0000000..8561717 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/Flugzeug.java @@ -0,0 +1,11 @@ +package pr2.oo.interfaces.java8; + +public class Flugzeug implements Flieger { + public void starten() { + System.out.println("starte"); + } + + public void landen() { + System.out.println("lande"); + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/IA.java b/src/main/java/pr2/oo/interfaces/java8/IA.java new file mode 100644 index 0000000..e6f8c01 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/IA.java @@ -0,0 +1,5 @@ +package pr2.oo.interfaces.java8; + +public interface IA { + public default void m() { } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/IB.java b/src/main/java/pr2/oo/interfaces/java8/IB.java new file mode 100644 index 0000000..476a2d1 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/IB.java @@ -0,0 +1,5 @@ +package pr2.oo.interfaces.java8; + +public interface IB { + public default void m() { } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/Impl.java b/src/main/java/pr2/oo/interfaces/java8/Impl.java new file mode 100644 index 0000000..36feded --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/Impl.java @@ -0,0 +1,5 @@ +package pr2.oo.interfaces.java8; + +public class Impl implements IA, IB { + public void m() { } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/Main.java b/src/main/java/pr2/oo/interfaces/java8/Main.java new file mode 100644 index 0000000..0783728 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/Main.java @@ -0,0 +1,11 @@ +package pr2.oo.interfaces.java8; + +public class Main { + public static void main(String[] args) { + Flugzeug flugzeug = new Flugzeug(); + flugzeug.starten(); + flugzeug.steigen(); + flugzeug.sinken(); + flugzeug.landen(); + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/Rechner.java b/src/main/java/pr2/oo/interfaces/java8/Rechner.java new file mode 100644 index 0000000..55bfe93 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/Rechner.java @@ -0,0 +1,10 @@ +package pr2.oo.interfaces.java8; + +public interface Rechner { + + public int apply(int a, int b); + + public static int rechne(Rechner r, int a, int b) { + return r.apply(a, b); + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/diamond/A.java b/src/main/java/pr2/oo/interfaces/java8/diamond/A.java new file mode 100644 index 0000000..8f28016 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/diamond/A.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.interfaces.java8.diamond; + +public class A implements I1 { + + public void methode() { + System.out.println("A"); + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/diamond/B.java b/src/main/java/pr2/oo/interfaces/java8/diamond/B.java new file mode 100644 index 0000000..660c641 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/diamond/B.java @@ -0,0 +1,10 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.interfaces.java8.diamond; + +public class B extends A { + + @Override + public void methode() { + System.out.println("B"); + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/diamond/C.java b/src/main/java/pr2/oo/interfaces/java8/diamond/C.java new file mode 100644 index 0000000..f30bd5b --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/diamond/C.java @@ -0,0 +1,6 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.interfaces.java8.diamond; + +public class C extends B implements I2 { + +} diff --git a/src/main/java/pr2/oo/interfaces/java8/diamond/I1.java b/src/main/java/pr2/oo/interfaces/java8/diamond/I1.java new file mode 100644 index 0000000..5e050d8 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/diamond/I1.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.interfaces.java8.diamond; + +public interface I1 { + + public default void methode() { + System.out.println("I1"); + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/diamond/I2.java b/src/main/java/pr2/oo/interfaces/java8/diamond/I2.java new file mode 100644 index 0000000..d08966d --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/diamond/I2.java @@ -0,0 +1,10 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.interfaces.java8.diamond; + +public interface I2 extends I1 { + + @Override + public default void methode() { + System.out.println("I2"); + } +} diff --git a/src/main/java/pr2/oo/interfaces/java8/diamond/Main.java b/src/main/java/pr2/oo/interfaces/java8/diamond/Main.java new file mode 100644 index 0000000..d7192b1 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/java8/diamond/Main.java @@ -0,0 +1,10 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.interfaces.java8.diamond; + +public class Main { + + public static void main(String[] args) { + C c = new C(); + c.methode(); + } +} diff --git a/src/main/java/pr2/oo/interfaces/mehrfachvererbung/A.java b/src/main/java/pr2/oo/interfaces/mehrfachvererbung/A.java new file mode 100644 index 0000000..1affe31 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/mehrfachvererbung/A.java @@ -0,0 +1,13 @@ +/* + * (c) 2010 Thomas Smits + */ +package pr2.oo.interfaces.mehrfachvererbung; + +public class A implements I1, I2 { + + public static void main(String[] args) { + //System.out.println(KONSTANTE); + System.out.println(I1.KONSTANTE); + System.out.println(I2.KONSTANTE); + } +} diff --git a/src/main/java/pr2/oo/interfaces/mehrfachvererbung/I1.java b/src/main/java/pr2/oo/interfaces/mehrfachvererbung/I1.java new file mode 100644 index 0000000..d126e65 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/mehrfachvererbung/I1.java @@ -0,0 +1,8 @@ +/* + * (c) 2010 Thomas Smits + */ +package pr2.oo.interfaces.mehrfachvererbung; + +public interface I1 { + public static final int KONSTANTE = 42; +} diff --git a/src/main/java/pr2/oo/interfaces/mehrfachvererbung/I2.java b/src/main/java/pr2/oo/interfaces/mehrfachvererbung/I2.java new file mode 100644 index 0000000..16c6b0c --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/mehrfachvererbung/I2.java @@ -0,0 +1,8 @@ +/* + * (c) 2010 Thomas Smits + */ +package pr2.oo.interfaces.mehrfachvererbung; + +public interface I2 { + public static final int KONSTANTE = 23; +} diff --git a/src/main/java/pr2/oo/interfaces/v1/Flieger.java b/src/main/java/pr2/oo/interfaces/v1/Flieger.java new file mode 100644 index 0000000..0e96c68 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v1/Flieger.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v1; + +public interface Flieger { + + public void starten(); + + public void landen(); + + public void fliegen(); +} diff --git a/src/main/java/pr2/oo/interfaces/v1/Flughafen.java b/src/main/java/pr2/oo/interfaces/v1/Flughafen.java new file mode 100644 index 0000000..6116b03 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v1/Flughafen.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v1; + +public class Flughafen { + + public static void main(String[] args) { + Flieger flieger = new Flugzeug(); + + flieger.landen(); + } +} diff --git a/src/main/java/pr2/oo/interfaces/v1/Flugzeug.java b/src/main/java/pr2/oo/interfaces/v1/Flugzeug.java new file mode 100644 index 0000000..d00e06a --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v1/Flugzeug.java @@ -0,0 +1,19 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v1; + +public class Flugzeug implements Flieger { + + public void fliegen() { + // ... + } + + public void landen() { + // ... + } + + public void starten() { + // .. + } +} diff --git a/src/main/java/pr2/oo/interfaces/v2/Flieger.java b/src/main/java/pr2/oo/interfaces/v2/Flieger.java new file mode 100644 index 0000000..44956d4 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v2/Flieger.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v2; + +public interface Flieger { + + int constant = 12; + + void starten(); + + void landen(); + + void fliegen(); +} diff --git a/src/main/java/pr2/oo/interfaces/v2/Flieger2.java b/src/main/java/pr2/oo/interfaces/v2/Flieger2.java new file mode 100644 index 0000000..cddf3d7 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v2/Flieger2.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v2; + +public interface Flieger2 { + + public static final int constant = 12; + + public abstract void starten(); + + public abstract void landen(); + + public abstract void fliegen(); +} diff --git a/src/main/java/pr2/oo/interfaces/v2/Flugzeug.java b/src/main/java/pr2/oo/interfaces/v2/Flugzeug.java new file mode 100644 index 0000000..997e780 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v2/Flugzeug.java @@ -0,0 +1,19 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v2; + +public class Flugzeug implements Flieger { + + public void fliegen() { + // ... + } + + public void landen() { + // ... + } + + public void starten() { + // .. + } +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Airbus.java b/src/main/java/pr2/oo/interfaces/v3/Airbus.java new file mode 100644 index 0000000..d7c4cbb --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Airbus.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public class Airbus extends Flugzeug { + +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Ente.java b/src/main/java/pr2/oo/interfaces/v3/Ente.java new file mode 100644 index 0000000..a619260 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Ente.java @@ -0,0 +1,22 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public class Ente extends Vogel implements Schwimmer, Flieger { + + public void eierLegen() { // ... + } + + public void schwimmen() { // ... + } + + public void fliegen() { // ... + } + + public void landen() { // ... + } + + public void starten() { // ... + } +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Flieger.java b/src/main/java/pr2/oo/interfaces/v3/Flieger.java new file mode 100644 index 0000000..3cbc1d7 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Flieger.java @@ -0,0 +1,10 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public interface Flieger { + public void starten(); + public void landen(); + public void fliegen(); +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Flugzeug.java b/src/main/java/pr2/oo/interfaces/v3/Flugzeug.java new file mode 100644 index 0000000..f01f524 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Flugzeug.java @@ -0,0 +1,19 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public class Flugzeug extends Maschine implements Flieger { + + public void fliegen() { + // ... + } + + public void landen() { + // ... + } + + public void starten() { + // .. + } +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Maschine.java b/src/main/java/pr2/oo/interfaces/v3/Maschine.java new file mode 100644 index 0000000..d71a29b --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Maschine.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public class Maschine { + +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Schwimmer.java b/src/main/java/pr2/oo/interfaces/v3/Schwimmer.java new file mode 100644 index 0000000..df2773b --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Schwimmer.java @@ -0,0 +1,9 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public interface Schwimmer { + + public void schwimmen(); +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Superman.java b/src/main/java/pr2/oo/interfaces/v3/Superman.java new file mode 100644 index 0000000..19c6113 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Superman.java @@ -0,0 +1,19 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public class Superman implements Flieger { + + public void fliegen() { // ... + } + + public void landen() { // ... + } + + public void starten() { // ... + } + + public void weltRetten() { // ... + } +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Tier.java b/src/main/java/pr2/oo/interfaces/v3/Tier.java new file mode 100644 index 0000000..2e44597 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Tier.java @@ -0,0 +1,9 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public abstract class Tier { + public void schlafen() { // ... + } +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Vogel.java b/src/main/java/pr2/oo/interfaces/v3/Vogel.java new file mode 100644 index 0000000..a921b06 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Vogel.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public abstract class Vogel extends Tier { + public abstract void eierLegen(); +} diff --git a/src/main/java/pr2/oo/interfaces/v3/Wasserflugzeug.java b/src/main/java/pr2/oo/interfaces/v3/Wasserflugzeug.java new file mode 100644 index 0000000..67e4721 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v3/Wasserflugzeug.java @@ -0,0 +1,10 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v3; + +public class Wasserflugzeug extends Flugzeug implements Schwimmer { + + public void schwimmen() { // ... + } +} diff --git a/src/main/java/pr2/oo/interfaces/v4/Konstanten.java b/src/main/java/pr2/oo/interfaces/v4/Konstanten.java new file mode 100644 index 0000000..6dc362f --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v4/Konstanten.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v4; + +public interface Konstanten { + public static final double PI = 3.14159265; +} diff --git a/src/main/java/pr2/oo/interfaces/v4/Mathe.java b/src/main/java/pr2/oo/interfaces/v4/Mathe.java new file mode 100644 index 0000000..bf37d1f --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v4/Mathe.java @@ -0,0 +1,11 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v4; + +public class Mathe implements Konstanten { + + public double kreisFlaeche(double radius) { + return PI*radius*radius; + } +} diff --git a/src/main/java/pr2/oo/interfaces/v4/Mathe2.java b/src/main/java/pr2/oo/interfaces/v4/Mathe2.java new file mode 100644 index 0000000..93113f8 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v4/Mathe2.java @@ -0,0 +1,11 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v4; + +public class Mathe2 { + + public double kreisFlaeche(double radius) { + return Konstanten.PI*radius*radius; + } +} diff --git a/src/main/java/pr2/oo/interfaces/v5/Sorter.java b/src/main/java/pr2/oo/interfaces/v5/Sorter.java new file mode 100644 index 0000000..c6f1b21 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v5/Sorter.java @@ -0,0 +1,19 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.interfaces.v5; + +import java.util.Arrays; + +public class Sorter { + + public static void main(String[] args) { + Telefonnummer[] nummern = { + new Telefonnummer(6221, 72643), + new Telefonnummer(7262, 5558912), + new Telefonnummer(6221, 71263), + new Telefonnummer(7261, 5558912) }; + + Arrays.sort(nummern); + + System.out.println(Arrays.asList(nummern).toString()); + } +} diff --git a/src/main/java/pr2/oo/interfaces/v5/Telefonnummer.java b/src/main/java/pr2/oo/interfaces/v5/Telefonnummer.java new file mode 100644 index 0000000..14f8678 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v5/Telefonnummer.java @@ -0,0 +1,40 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.interfaces.v5; + +@SuppressWarnings("rawtypes") +public class Telefonnummer implements Comparable { + + private int vorwahl; + private int nummer; + + public int compareTo(Object o) { + Telefonnummer n = (Telefonnummer) o; + + if (vorwahl > n.vorwahl) { + return 1; + } else if (vorwahl < n.vorwahl) { + return -1; + } else { + // vorwahl == n.vorwahl + if (nummer > n.nummer) { + return 1; + } else if (nummer < n.nummer) { + return -1; + } + } + + return 0; + } + + public Telefonnummer(int vorwahl, int nummer) { + this.vorwahl = vorwahl; + this.nummer = nummer; + } + + @Override + public String toString() { + return String.format("(%d) %d", vorwahl, nummer); + } +} diff --git a/src/main/java/pr2/oo/interfaces/v6/A.java b/src/main/java/pr2/oo/interfaces/v6/A.java new file mode 100644 index 0000000..8535756 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v6/A.java @@ -0,0 +1,8 @@ +/* + * (c) 2010 Thomas Smits + */ +package pr2.oo.interfaces.v6; + +public class A implements I1 { + public void m1() { /* leer */ } +} diff --git a/src/main/java/pr2/oo/interfaces/v6/B.java b/src/main/java/pr2/oo/interfaces/v6/B.java new file mode 100644 index 0000000..c444e65 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v6/B.java @@ -0,0 +1,8 @@ +/* + * (c) 2010 Thomas Smits + */ +package pr2.oo.interfaces.v6; + +public class B extends A implements I2 { + public void m2() { /* leer */ } +} diff --git a/src/main/java/pr2/oo/interfaces/v6/I1.java b/src/main/java/pr2/oo/interfaces/v6/I1.java new file mode 100644 index 0000000..48e625b --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v6/I1.java @@ -0,0 +1,8 @@ +/* + * (c) 2010 Thomas Smits + */ +package pr2.oo.interfaces.v6; + +public interface I1 { + public abstract void m1(); +} diff --git a/src/main/java/pr2/oo/interfaces/v6/I2.java b/src/main/java/pr2/oo/interfaces/v6/I2.java new file mode 100644 index 0000000..d9980f5 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v6/I2.java @@ -0,0 +1,8 @@ +/* + * (c) 2010 Thomas Smits + */ +package pr2.oo.interfaces.v6; + +public interface I2 { + public abstract void m2(); +} diff --git a/src/main/java/pr2/oo/interfaces/v6/Main.java b/src/main/java/pr2/oo/interfaces/v6/Main.java new file mode 100644 index 0000000..4e8d234 --- /dev/null +++ b/src/main/java/pr2/oo/interfaces/v6/Main.java @@ -0,0 +1,18 @@ +/* + * (c) 2010 Thomas Smits + */ +package pr2.oo.interfaces.v6; + +public class Main { + public static void main(String[] args) { + A a = new A(); + B b = new B(); + + System.out.println(a instanceof I1); // --> true + System.out.println(a instanceof I2); // --> false + System.out.println(b instanceof A); // --> true + System.out.println(b instanceof I1); // --> true + System.out.println(b instanceof I2); // --> true + + } +} diff --git a/src/main/java/pr2/oo/konstruktor/hierarchie/A.java b/src/main/java/pr2/oo/konstruktor/hierarchie/A.java new file mode 100644 index 0000000..8d86856 --- /dev/null +++ b/src/main/java/pr2/oo/konstruktor/hierarchie/A.java @@ -0,0 +1,14 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.konstruktor.hierarchie; + +public class A extends Object { + + protected int i; + + public A(int i) { + this.i = i; + } + +} diff --git a/src/main/java/pr2/oo/konstruktor/hierarchie/B.java b/src/main/java/pr2/oo/konstruktor/hierarchie/B.java new file mode 100644 index 0000000..5d856fb --- /dev/null +++ b/src/main/java/pr2/oo/konstruktor/hierarchie/B.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.konstruktor.hierarchie; + +public class B extends A { + + protected int k; + + public B(int k) { + this(k, 0); + } + + public B(int k, int i) { + super(i); + } +} diff --git a/src/main/java/pr2/oo/konstruktor/probleme/A.java b/src/main/java/pr2/oo/konstruktor/probleme/A.java new file mode 100644 index 0000000..d81331d --- /dev/null +++ b/src/main/java/pr2/oo/konstruktor/probleme/A.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.konstruktor.probleme; + +public class A { + + protected String name; + + public A() { + name = getDetails(); + } + + protected String getDetails() { + return "Hans"; + } +} diff --git a/src/main/java/pr2/oo/konstruktor/probleme/B.java b/src/main/java/pr2/oo/konstruktor/probleme/B.java new file mode 100644 index 0000000..5889297 --- /dev/null +++ b/src/main/java/pr2/oo/konstruktor/probleme/B.java @@ -0,0 +1,21 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.konstruktor.probleme; + +public class B extends A { + + protected String info = "Eine Information"; + + public B() { + } + + protected String getDetails() { + return name + info.length(); + } + + public static void main(String[] args) { + B b = new B(); + System.out.println(b.getDetails()); + } +} diff --git a/src/main/java/pr2/oo/object/clone/CloneDemo.java b/src/main/java/pr2/oo/object/clone/CloneDemo.java new file mode 100644 index 0000000..1df7ded --- /dev/null +++ b/src/main/java/pr2/oo/object/clone/CloneDemo.java @@ -0,0 +1,16 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.object.clone; + +public class CloneDemo { + + public static void main(String[] args) throws CloneNotSupportedException { + Mitarbeiter m1 = new Mitarbeiter("Heinz", 5000.00, null); + Mitarbeiter m2 = (Mitarbeiter) m1.clone(); + + System.out.println(m1 == m2); + System.out.println(m2.name); + System.out.println(m2.gehalt); + } +} diff --git a/src/main/java/pr2/oo/object/clone/Mitarbeiter.java b/src/main/java/pr2/oo/object/clone/Mitarbeiter.java new file mode 100644 index 0000000..17b915d --- /dev/null +++ b/src/main/java/pr2/oo/object/clone/Mitarbeiter.java @@ -0,0 +1,26 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.object.clone; + +import java.util.Date; + +public class Mitarbeiter implements Cloneable { + public String name; + public double gehalt; + public Date geburtsdatum; + + public Mitarbeiter(String name, double gehalt, Date geburtsdatum) { + this.name = name; + this.gehalt = gehalt; + this.geburtsdatum = geburtsdatum; + } + + protected Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError("Cannot happen"); + } + } +} diff --git a/src/main/java/pr2/oo/object/clone2/Main.java b/src/main/java/pr2/oo/object/clone2/Main.java new file mode 100644 index 0000000..7ecfe03 --- /dev/null +++ b/src/main/java/pr2/oo/object/clone2/Main.java @@ -0,0 +1,29 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.object.clone2; + +/** + * + * + * @author Thomas Smits + */ +public class Main { + + public static void main(String[] args) throws CloneNotSupportedException { + Schaf dolly = new Schaf("Dolly"); + Schaf shawn = new Schaf("Shawn"); + dolly.setFreund(shawn); + shawn.setFreund(dolly); + + + Schaf dolly2 = (Schaf) dolly.clone(); + dolly2.ohrmarkennummer = 42; + + System.out.println(dolly); + System.out.println("Ist befreundet mit " + dolly.getFreund()); + System.out.println("Cloning in Progress... all your sheep belong to us"); + System.out.println(dolly2); + System.out.println("Ist befreundet mit " + dolly2.getFreund()); + + + } +} diff --git a/src/main/java/pr2/oo/object/clone2/Schaf.java b/src/main/java/pr2/oo/object/clone2/Schaf.java new file mode 100644 index 0000000..85fc9d1 --- /dev/null +++ b/src/main/java/pr2/oo/object/clone2/Schaf.java @@ -0,0 +1,48 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.object.clone2; + +import java.util.Random; + +/** + * + * + * @author Thomas Smits + */ +public class Schaf implements Cloneable { + + public static int schafCounter = 0; + + private String name; + private Schaf freund; + public int ohrmarkennummer = new Random().nextInt(10000); + + public Schaf(String name) { + this.name = name; + System.out.printf("Konstruktor gerufen für Schaf %s%n", name); + } + + public void setFreund(Schaf freund) { + this.freund = freund; + } + + public Schaf getFreund() { + return freund; + } + + @Override + public String toString() { + return String.format("Ich heisse %s (Nummer %d, code %d), " + + "mein Freund heisst %s", + name, ohrmarkennummer, System.identityHashCode(this), + freund != null ? freund.name : "Du hast keine Freunde!!!!"); + } + + @Override + protected Object clone() throws CloneNotSupportedException { + schafCounter++; + System.out.println(schafCounter); + Schaf miniMi = (Schaf) super.clone(); + miniMi.freund = ((freund == null) ? null : (Schaf) freund.clone()); + return miniMi; + } +} diff --git a/src/main/java/pr2/oo/object/equals/EqualsDemo.java b/src/main/java/pr2/oo/object/equals/EqualsDemo.java new file mode 100644 index 0000000..3e209b8 --- /dev/null +++ b/src/main/java/pr2/oo/object/equals/EqualsDemo.java @@ -0,0 +1,21 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.object.equals; + +public class EqualsDemo { + + public static void main(String[] args) { + MeinDatum d1 = new MeinDatum(5, 12, 2009); + MeinDatum d2 = new MeinDatum(5, 12, 2009); + MeinDatum d3 = new MeinDatum(3, 7, 1970); + + System.out.println(d1 == d2); + System.out.println(d1.equals(d2)); + System.out.println(d1.equals(d3)); + + d2 = d1; + + System.out.println(d1 == d2); + } +} diff --git a/src/main/java/pr2/oo/object/equals/MeinDatum.java b/src/main/java/pr2/oo/object/equals/MeinDatum.java new file mode 100644 index 0000000..40a9150 --- /dev/null +++ b/src/main/java/pr2/oo/object/equals/MeinDatum.java @@ -0,0 +1,42 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.object.equals; + +public class MeinDatum { + int tag; + int monat; + int jahr; + + public MeinDatum(int tag, int monat, int jahr) { + this.tag = tag; + this.monat = monat; + this.jahr = jahr; + } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + jahr; + result = prime * result + monat; + result = prime * result + tag; + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MeinDatum other = (MeinDatum) obj; + if (jahr != other.jahr) + return false; + if (monat != other.monat) + return false; + if (tag != other.tag) + return false; + return true; + } +} diff --git a/src/main/java/pr2/oo/object/equals/Mitarbeiter.java b/src/main/java/pr2/oo/object/equals/Mitarbeiter.java new file mode 100644 index 0000000..3478c10 --- /dev/null +++ b/src/main/java/pr2/oo/object/equals/Mitarbeiter.java @@ -0,0 +1,62 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.object.equals; + +import java.util.Date; + +public class Mitarbeiter { + + public String name; + public double gehalt; + public Date geburtsdatum; + + public Mitarbeiter(String name, double gehalt, Date geburtsdatum) { + super(); + this.name = name; + this.gehalt = gehalt; + this.geburtsdatum = geburtsdatum; + } + + public boolean equals(Object o) { + + if (o == null) { + return false; + } + else if (o == this) { + return true; + } + else if (o instanceof Mitarbeiter) { + Mitarbeiter mi = (Mitarbeiter) o; + + return mi.name.equals(name) + && mi.gehalt == gehalt + && mi.geburtsdatum.equals(geburtsdatum); + } + else { + return false; + } + } + + public int hashCode() { + return name.hashCode() + ^ (int) Double.doubleToLongBits(gehalt) + ^ geburtsdatum.hashCode(); + } + + public void doIt(Mitarbeiter m) { + System.out.println(m + " hat ein Gehalt von " + gehalt); + System.out.println(m.toString() + " hat ein Gehalt von " + Double.toString(gehalt)); + } + + public String toString() { + return "Mitarbeiter [name: " + name + ", " + + "gehalt: " + gehalt + ", " + + "geburtsdatum " + geburtsdatum + "]"; + } + + public static void main(String[] args) { + Mitarbeiter m = new Mitarbeiter("Franz Meier", 5000.00, new Date(new Date().getTime() - 1000L*1000*1000*1000)); + m.doIt(m); + } +} diff --git a/src/main/java/pr2/oo/object/intern/InternDemo.java b/src/main/java/pr2/oo/object/intern/InternDemo.java new file mode 100644 index 0000000..e59cc3a --- /dev/null +++ b/src/main/java/pr2/oo/object/intern/InternDemo.java @@ -0,0 +1,22 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.object.intern; + +public class InternDemo { + public static void main(String[] args) { + String s1 = "Hallo"; + String s2 = "Hallo"; + String s3 = new String("Hallo"); + String s4 = s3.intern(); + + System.out.println(s1 == s2); // -> true + System.out.println(s1 == s3); // -> false + System.out.println(s1 == s4); // -> true + + String s = ""; + + if ((s != null) && (s.equals("text"))) {} + if ("text".equals(s)) {} + } +} diff --git a/src/main/java/pr2/oo/quiz/Ente.java b/src/main/java/pr2/oo/quiz/Ente.java new file mode 100644 index 0000000..3f5fd9d --- /dev/null +++ b/src/main/java/pr2/oo/quiz/Ente.java @@ -0,0 +1,20 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz; + +public class Ente { + + private static final Ente INSTANCE = new Ente(); + private static final int NORMAL_GROESSE = Integer.parseInt("12"); + + private int groesse = NORMAL_GROESSE - 10; + + public int getGroesse() { + return groesse; + } + + public static void main(String[] args) { + System.out.println(INSTANCE.getGroesse()); + } +} diff --git a/src/main/java/pr2/oo/quiz/Initializer.java b/src/main/java/pr2/oo/quiz/Initializer.java new file mode 100644 index 0000000..af34a03 --- /dev/null +++ b/src/main/java/pr2/oo/quiz/Initializer.java @@ -0,0 +1,21 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz; + +public class Initializer { + + static { + initialize(); + } + + private static boolean initialized = false; + + private static void initialize() { + initialized = true; + } + + public static void main(String[] args) { + System.out.println(initialized); + } +} diff --git a/src/main/java/pr2/oo/quiz/QuizStatic.java b/src/main/java/pr2/oo/quiz/QuizStatic.java new file mode 100644 index 0000000..3ba70c9 --- /dev/null +++ b/src/main/java/pr2/oo/quiz/QuizStatic.java @@ -0,0 +1,16 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz; + +public class QuizStatic { + + @SuppressWarnings("static-access") + public static void main(String[] args) { + String b = null; + System.out.println(b.valueOf(15)); + + System.out.println(((String) null).valueOf(17)); + + } +} diff --git a/src/main/java/pr2/oo/quiz/binding/BindingQuiz.java b/src/main/java/pr2/oo/quiz/binding/BindingQuiz.java new file mode 100644 index 0000000..f86b1aa --- /dev/null +++ b/src/main/java/pr2/oo/quiz/binding/BindingQuiz.java @@ -0,0 +1,31 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.binding; + +class A { +} + +class B extends A { +} + +public class BindingQuiz { + + public static void f(A a) { + System.out.println("A"); + } + + public static void f(B b) { + System.out.println("B"); + } + + public static void main(String[] args) { + A a1 = new A(); + A a2 = new B(); + B b = new B(); + + f(a1); + f(a2); + f(b); + } +} diff --git a/src/main/java/pr2/oo/quiz/boxing/BoxingQuiz.java b/src/main/java/pr2/oo/quiz/boxing/BoxingQuiz.java new file mode 100644 index 0000000..0d1556a --- /dev/null +++ b/src/main/java/pr2/oo/quiz/boxing/BoxingQuiz.java @@ -0,0 +1,16 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.boxing; + +public class BoxingQuiz { + + public static void main(String[] args) { + Long l1 = 150L; + Long l2 = 200L; + + l2 = l2 - 50; + + System.out.println(l1 == l2); + } +} diff --git a/src/main/java/pr2/oo/quiz/constructor/ConstructorQuiz.java b/src/main/java/pr2/oo/quiz/constructor/ConstructorQuiz.java new file mode 100644 index 0000000..779619b --- /dev/null +++ b/src/main/java/pr2/oo/quiz/constructor/ConstructorQuiz.java @@ -0,0 +1,19 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.constructor; + +class A { + public A() { System.out.println("A"); } +} + +class B extends A { + public B() { System.out.println("B"); } +} + +public class ConstructorQuiz { + + public static void main(String[] args) { + new B(); + } +} diff --git a/src/main/java/pr2/oo/quiz/constructor/NameHolder.java b/src/main/java/pr2/oo/quiz/constructor/NameHolder.java new file mode 100644 index 0000000..73b8f9b --- /dev/null +++ b/src/main/java/pr2/oo/quiz/constructor/NameHolder.java @@ -0,0 +1,23 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.constructor; + +public class NameHolder { + + private String name; + + public void NameHolder() { + name = "Hallo"; + } + + @Override + public String toString() { + return name; + } + + public static void main(String[] args) { + NameHolder s = new NameHolder(); + System.out.println(s); + } +} diff --git a/src/main/java/pr2/oo/quiz/equals/A.java b/src/main/java/pr2/oo/quiz/equals/A.java new file mode 100644 index 0000000..217ad93 --- /dev/null +++ b/src/main/java/pr2/oo/quiz/equals/A.java @@ -0,0 +1,32 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.equals; + +public class A { + + public int i; + + public boolean equals(A obj) { + return ((obj != null) + && (getClass() == obj.getClass()) + && (i == ((A) obj).i)); + } + + public int hashCode() { + return i; + } + + public static void main(String[] args) { + A a1 = new A(); + a1.i = 5; + + A a2 = new A(); + a2.i = 5; + + Object o = a2; + + System.out.println("a1.equals(a2): " + a1.equals(a2)); + System.out.println("a1.equals(o): " + a1.equals(o)); + } +} diff --git a/src/main/java/pr2/oo/quiz/equals2/A.java b/src/main/java/pr2/oo/quiz/equals2/A.java new file mode 100644 index 0000000..dab8cad --- /dev/null +++ b/src/main/java/pr2/oo/quiz/equals2/A.java @@ -0,0 +1,32 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.equals2; + +public class A { + + public int i; + + public boolean equals(Object obj) { + return ((obj != null) + && (getClass() == obj.getClass()) + && (i == ((A) obj).i)); + } + + public int hashCode() { + return i; + } + + public static void main(String[] args) { + A a1 = new A(); + a1.i = 5; + + A a2 = new A(); + a2.i = 5; + + Object o = a2; + + System.out.println("a1.equals(a2): " + a1.equals(a2)); + System.out.println("a1.equals(o): " + a1.equals(o)); + } +} diff --git a/src/main/java/pr2/oo/quiz/polymorphie/Polymorphie.java b/src/main/java/pr2/oo/quiz/polymorphie/Polymorphie.java new file mode 100644 index 0000000..c8a6d3c --- /dev/null +++ b/src/main/java/pr2/oo/quiz/polymorphie/Polymorphie.java @@ -0,0 +1,29 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.polymorphie; + +class A { + public void f() { + System.out.println("A"); + } +} + +class B extends A { + public void f() { + System.out.println("B"); + } +} + +public class Polymorphie { + + public static void main(String[] args) { + A a1 = new A(); + A a2 = new B(); + B b = new B(); + + a1.f(); + a2.f(); + b.f(); + } +} diff --git a/src/main/java/pr2/oo/quiz/verdecken/A.java b/src/main/java/pr2/oo/quiz/verdecken/A.java new file mode 100644 index 0000000..3f08de5 --- /dev/null +++ b/src/main/java/pr2/oo/quiz/verdecken/A.java @@ -0,0 +1,14 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.verdecken; + +class A { + + private int k = 10; + public int j = 20; + + public void f() { + System.out.println(k); + } +} diff --git a/src/main/java/pr2/oo/quiz/verdecken/B.java b/src/main/java/pr2/oo/quiz/verdecken/B.java new file mode 100644 index 0000000..6aad39d --- /dev/null +++ b/src/main/java/pr2/oo/quiz/verdecken/B.java @@ -0,0 +1,19 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.verdecken; + +public class B extends A { + + private int j = 3000; + + public static void main(String[] args) { + + A a = new A(); + A b = new B(); + B b2 = new B(); + + System.out.printf("%d %d %d%n", a.j, b.j, b2.j); + a.f(); + } +} diff --git a/src/main/java/pr2/oo/quiz/vererbung/C.java b/src/main/java/pr2/oo/quiz/vererbung/C.java new file mode 100644 index 0000000..7da4e1d --- /dev/null +++ b/src/main/java/pr2/oo/quiz/vererbung/C.java @@ -0,0 +1,19 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.quiz.vererbung; + +class A { + +} + +class B extends A { + +} + +//public class C extends A, B { +// +// public C() { +// super(null); +// } +//} diff --git a/src/main/java/pr2/oo/statisch/apiimpl/Calculator.java b/src/main/java/pr2/oo/statisch/apiimpl/Calculator.java new file mode 100644 index 0000000..9f90795 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/apiimpl/Calculator.java @@ -0,0 +1,9 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.apiimpl; + +public interface Calculator { + public abstract int add(int a, int b); + public abstract int sub(int a, int b); +} diff --git a/src/main/java/pr2/oo/statisch/apiimpl/CalculatorFactory.java b/src/main/java/pr2/oo/statisch/apiimpl/CalculatorFactory.java new file mode 100644 index 0000000..fb7dca7 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/apiimpl/CalculatorFactory.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.apiimpl; + +public class CalculatorFactory { + + private CalculatorFactory() {} + + public static Calculator createCalculator() { + return new CalculatorImpl(); + } +} diff --git a/src/main/java/pr2/oo/statisch/apiimpl/CalculatorImpl.java b/src/main/java/pr2/oo/statisch/apiimpl/CalculatorImpl.java new file mode 100644 index 0000000..ae5f6dd --- /dev/null +++ b/src/main/java/pr2/oo/statisch/apiimpl/CalculatorImpl.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.apiimpl; + +public class CalculatorImpl implements Calculator { + + public int add(int a, int b) { + return a + b; + } + + public int sub(int a, int b) { + return a - b; + } +} diff --git a/src/main/java/pr2/oo/statisch/apiimpl/CalculatorImplQuantumSuperDuper.java b/src/main/java/pr2/oo/statisch/apiimpl/CalculatorImplQuantumSuperDuper.java new file mode 100644 index 0000000..ff8d237 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/apiimpl/CalculatorImplQuantumSuperDuper.java @@ -0,0 +1,22 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.statisch.apiimpl; + +public class CalculatorImplQuantumSuperDuper implements Calculator { + + @Override + public int add(int a, int b) { + Integer ai = a; + Integer bi = b; + Integer r = ai + bi; + return r; + } + + @Override + public int sub(int a, int b) { + Integer ai = a; + Integer bi = b; + Integer r = ai - bi; + return r; + } + +} diff --git a/src/main/java/pr2/oo/statisch/apiimpl/Verwender.java b/src/main/java/pr2/oo/statisch/apiimpl/Verwender.java new file mode 100644 index 0000000..18420d9 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/apiimpl/Verwender.java @@ -0,0 +1,14 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.apiimpl; + +public class Verwender { + + public static void main(String[] args) { + + Calculator calculator = CalculatorFactory.createCalculator(); + int ergebnis = calculator.add(1, 5); + System.out.println(ergebnis); + } +} diff --git a/src/main/java/pr2/oo/statisch/cycle/A.java b/src/main/java/pr2/oo/statisch/cycle/A.java new file mode 100644 index 0000000..595e2b1 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/cycle/A.java @@ -0,0 +1,16 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.statisch.cycle; + +public class A { + + static B b; + + static { + b = new B(); + System.out.println("static A"); + } + + A() { + System.out.println("A():" + b); + } +} diff --git a/src/main/java/pr2/oo/statisch/cycle/B.java b/src/main/java/pr2/oo/statisch/cycle/B.java new file mode 100644 index 0000000..d0fed66 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/cycle/B.java @@ -0,0 +1,16 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.statisch.cycle; + +public class B { + + static A a; + + static { + a = new A(); + System.out.println("static B"); + } + + B() { + System.out.println("B():" + a); + } +} diff --git a/src/main/java/pr2/oo/statisch/cycle/C.java b/src/main/java/pr2/oo/statisch/cycle/C.java new file mode 100644 index 0000000..5121aa6 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/cycle/C.java @@ -0,0 +1,10 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.statisch.cycle; + +public class C { + + public static void main(String[] args) throws Exception { + System.out.println("main: A.b = " + A.b); + System.out.println("main: B.a = " + B.a); + } +} diff --git a/src/main/java/pr2/oo/statisch/factory/Erzeugter.java b/src/main/java/pr2/oo/statisch/factory/Erzeugter.java new file mode 100644 index 0000000..e38c0b7 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/factory/Erzeugter.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.factory; + +public class Erzeugter { + + int wert; + + Erzeugter(int wert) { + this.wert = wert; + } +} diff --git a/src/main/java/pr2/oo/statisch/factory/Factory.java b/src/main/java/pr2/oo/statisch/factory/Factory.java new file mode 100644 index 0000000..08d7cc4 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/factory/Factory.java @@ -0,0 +1,11 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.factory; + +public class Factory { + + public static Erzeugter create(int wert) { + return new Erzeugter(wert); + } +} diff --git a/src/main/java/pr2/oo/statisch/initializer/Crash.java b/src/main/java/pr2/oo/statisch/initializer/Crash.java new file mode 100644 index 0000000..ede467d --- /dev/null +++ b/src/main/java/pr2/oo/statisch/initializer/Crash.java @@ -0,0 +1,13 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.statisch.initializer; + +public class Crash { + + static { + int x = 5 / 0; + } + + public static int add(int a, int b) { + return a + b; + } +} diff --git a/src/main/java/pr2/oo/statisch/initializer/CrashUser.java b/src/main/java/pr2/oo/statisch/initializer/CrashUser.java new file mode 100644 index 0000000..70ff2bc --- /dev/null +++ b/src/main/java/pr2/oo/statisch/initializer/CrashUser.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.statisch.initializer; + +public class CrashUser { + + public static void main(String[] args) { + System.out.println(Crash.add(5, 5)); + } +} diff --git a/src/main/java/pr2/oo/statisch/singleton/Broken.java b/src/main/java/pr2/oo/statisch/singleton/Broken.java new file mode 100644 index 0000000..9060469 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/singleton/Broken.java @@ -0,0 +1,25 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.singleton; + +public class Broken { + + private static Broken instanz; + + private Broken() { + // Keine Instanzen! + } + + public static Broken getInstance() { + if (instanz == null) { + synchronized (Broken.class) { + if (instanz == null) { + instanz = new Broken(); + } + } + } + + return instanz; + } +} diff --git a/src/main/java/pr2/oo/statisch/singleton/Firma.java b/src/main/java/pr2/oo/statisch/singleton/Firma.java new file mode 100644 index 0000000..11b85e5 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/singleton/Firma.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.singleton; + +public class Firma { + + private static final Firma instanz = new Firma(); + + public static Firma getInstance() { + return instanz; + } + + private Firma() { + // Keine Instanzen dieser Klasse! + } +} diff --git a/src/main/java/pr2/oo/statisch/singleton/Firma2.java b/src/main/java/pr2/oo/statisch/singleton/Firma2.java new file mode 100644 index 0000000..5c17a0d --- /dev/null +++ b/src/main/java/pr2/oo/statisch/singleton/Firma2.java @@ -0,0 +1,21 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.singleton; + +public class Firma2 { + + private static final Firma2 instanz; + + static { + instanz = new Firma2(); + } + + public static Firma2 getInstance() { + return instanz; + } + + private Firma2() { + // Keine Instanzen dieser Klasse! + } +} diff --git a/src/main/java/pr2/oo/statisch/v1/Ticket.java b/src/main/java/pr2/oo/statisch/v1/Ticket.java new file mode 100644 index 0000000..a3bd993 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/v1/Ticket.java @@ -0,0 +1,18 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.v1; + +public class Ticket { + + public static int zaehler = 0; + + private int serienNummer; + private String spiel; + + public Ticket(String spiel) { + zaehler++; + serienNummer = zaehler; + this.spiel = spiel; + } +} diff --git a/src/main/java/pr2/oo/statisch/v2/TestTicket.java b/src/main/java/pr2/oo/statisch/v2/TestTicket.java new file mode 100644 index 0000000..d5fe5f9 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/v2/TestTicket.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.v2; + +public class TestTicket { + public static void main(String[] args) { + + Ticket t1 = new Ticket("Dortmund-Schalke"); + System.out.println(Ticket.getZaehler()); + + Ticket t2 = new Ticket("Hoffenheim-Leverkusen"); + System.out.println(Ticket.getZaehler()); + } +} diff --git a/src/main/java/pr2/oo/statisch/v2/Ticket.java b/src/main/java/pr2/oo/statisch/v2/Ticket.java new file mode 100644 index 0000000..3a3c5bd --- /dev/null +++ b/src/main/java/pr2/oo/statisch/v2/Ticket.java @@ -0,0 +1,22 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.v2; + +public class Ticket { + + private static int zaehler = 0; + + private int serienNummer; + private String spiel; + + public Ticket(String spiel) { + zaehler++; + serienNummer = zaehler; + this.spiel = spiel; + } + + public static int getZaehler() { + return zaehler; + } +} diff --git a/src/main/java/pr2/oo/statisch/v3/TestTicket.java b/src/main/java/pr2/oo/statisch/v3/TestTicket.java new file mode 100644 index 0000000..dc61023 --- /dev/null +++ b/src/main/java/pr2/oo/statisch/v3/TestTicket.java @@ -0,0 +1,14 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.v3; + +public class TestTicket { + public static void main(String[] args) { + + Ticket t1 = new Ticket("Dortmund-Schalke"); + System.out.println(Ticket.getZaehler()); + Ticket t2 = new Ticket("Hoffenheim-Leverkusen"); + System.out.println(Ticket.getZaehler()); + } +} diff --git a/src/main/java/pr2/oo/statisch/v3/Ticket.java b/src/main/java/pr2/oo/statisch/v3/Ticket.java new file mode 100644 index 0000000..eae773e --- /dev/null +++ b/src/main/java/pr2/oo/statisch/v3/Ticket.java @@ -0,0 +1,30 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.v3; + +public class Ticket { + + private static int zaehler; + + private int serienNummer; + private String spiel; + + static { + zaehler = Integer.parseInt(System.getProperty("zaehler_start")); + } + + public Ticket(String spiel) { + zaehler++; + serienNummer = zaehler; + this.spiel = spiel; + } + + static { + System.out.println("Ticket initialisiert: zaehler=" + zaehler); + } + + public static int getZaehler() { + return zaehler; + } +} diff --git a/src/main/java/pr2/oo/statisch/v4/A.java b/src/main/java/pr2/oo/statisch/v4/A.java new file mode 100644 index 0000000..fed681f --- /dev/null +++ b/src/main/java/pr2/oo/statisch/v4/A.java @@ -0,0 +1,11 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.v4; + +public class A { + + public static void tuWas() { + System.out.println("A:tuWas()"); + } +} diff --git a/src/main/java/pr2/oo/statisch/v4/B.java b/src/main/java/pr2/oo/statisch/v4/B.java new file mode 100644 index 0000000..24e913d --- /dev/null +++ b/src/main/java/pr2/oo/statisch/v4/B.java @@ -0,0 +1,11 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.v4; + +public class B extends A { + + public static void tuWas() { + System.out.println("B:tuWas()"); + } +} diff --git a/src/main/java/pr2/oo/statisch/v4/Test.java b/src/main/java/pr2/oo/statisch/v4/Test.java new file mode 100644 index 0000000..724829c --- /dev/null +++ b/src/main/java/pr2/oo/statisch/v4/Test.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.statisch.v4; + +public class Test { + + @SuppressWarnings("static-access") + public static void main(String[] args) { + A a1 = new A(); + B b = new B(); + A a2 = new B(); + a1.tuWas(); + b.tuWas(); + a2.tuWas(); + } +} diff --git a/src/main/java/pr2/oo/ueberschreiben/A.java b/src/main/java/pr2/oo/ueberschreiben/A.java new file mode 100644 index 0000000..c4e8042 --- /dev/null +++ b/src/main/java/pr2/oo/ueberschreiben/A.java @@ -0,0 +1,19 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.ueberschreiben; + +class A { + + public void method(Object o) { + // ... + } +} + +class B extends A { + +// @Override + public void method(String o) { + // ... + } +} \ No newline at end of file diff --git a/src/main/java/pr2/oo/ueberschreiben/rueckgabetyp/A.java b/src/main/java/pr2/oo/ueberschreiben/rueckgabetyp/A.java new file mode 100644 index 0000000..496e637 --- /dev/null +++ b/src/main/java/pr2/oo/ueberschreiben/rueckgabetyp/A.java @@ -0,0 +1,11 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.ueberschreiben.rueckgabetyp; + +public class A { + + protected int methode() { + return 0; + } +} diff --git a/src/main/java/pr2/oo/ueberschreiben/rueckgabetyp/B.java b/src/main/java/pr2/oo/ueberschreiben/rueckgabetyp/B.java new file mode 100644 index 0000000..e9739a7 --- /dev/null +++ b/src/main/java/pr2/oo/ueberschreiben/rueckgabetyp/B.java @@ -0,0 +1,11 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.ueberschreiben.rueckgabetyp; + +public class B extends A { + + public int methode() { + return 0; + } +} diff --git a/src/main/java/pr2/oo/verdecken/A.java b/src/main/java/pr2/oo/verdecken/A.java new file mode 100644 index 0000000..5e74341 --- /dev/null +++ b/src/main/java/pr2/oo/verdecken/A.java @@ -0,0 +1,20 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.verdecken; + +public class A { + public int i = 5; + + public void doIt() { + System.out.println(i); + } + + public static void main(String[] args) { + A a = new A(); + B b = new B(); + a.doIt(); + b.doIt(); + b.doItNew(); + } +} diff --git a/src/main/java/pr2/oo/verdecken/B.java b/src/main/java/pr2/oo/verdecken/B.java new file mode 100644 index 0000000..337a437 --- /dev/null +++ b/src/main/java/pr2/oo/verdecken/B.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.verdecken; + +public class B extends A { + public String i = "Ein String in B"; + + public void doItNew() { + System.out.println(i); + System.out.println(super.i); + } +} diff --git a/src/main/java/pr2/oo/verdecken/C.java b/src/main/java/pr2/oo/verdecken/C.java new file mode 100644 index 0000000..092cd4a --- /dev/null +++ b/src/main/java/pr2/oo/verdecken/C.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.verdecken; + +public class C { + public int i = 1; +} diff --git a/src/main/java/pr2/oo/verdecken/D.java b/src/main/java/pr2/oo/verdecken/D.java new file mode 100644 index 0000000..a24e614 --- /dev/null +++ b/src/main/java/pr2/oo/verdecken/D.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.verdecken; + +public class D extends C { + private int i; // verdeckt i aus C mit private Sichtbarkeit +} diff --git a/src/main/java/pr2/oo/verdecken/E.java b/src/main/java/pr2/oo/verdecken/E.java new file mode 100644 index 0000000..e376d28 --- /dev/null +++ b/src/main/java/pr2/oo/verdecken/E.java @@ -0,0 +1,12 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.verdecken; + +public class E extends D { +// public void doIt() { +// i++; // Fehler, i wurde von D mit private verdeckt und +// // ist daher nicht mehr sichtbar. +// super.i++; // Fehler, da es in D kein sichtbares i gibt +// } +} diff --git a/src/main/java/pr2/oo/verdecken/ellipse/EllipseDemo.java b/src/main/java/pr2/oo/verdecken/ellipse/EllipseDemo.java new file mode 100644 index 0000000..53de05d --- /dev/null +++ b/src/main/java/pr2/oo/verdecken/ellipse/EllipseDemo.java @@ -0,0 +1,23 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.verdecken.ellipse; + +public class EllipseDemo { + + public void flexibleMethode(String name, int ... attributes) { + int summe = 0; + + for (int i = 0; i < attributes.length; i++) { + summe += attributes[i]; + } + + System.out.println(name + " ist " + summe); + } + + public static void main(String[] args) { + EllipseDemo demo = new EllipseDemo(); + demo.flexibleMethode("Primsumme bis 13", 1, 3, 5, 7, 13); + demo.flexibleMethode("Gar nichts"); + } +} diff --git a/src/main/java/pr2/oo/verdecken/ellipse/EllipseDetails.java b/src/main/java/pr2/oo/verdecken/ellipse/EllipseDetails.java new file mode 100644 index 0000000..98314cd --- /dev/null +++ b/src/main/java/pr2/oo/verdecken/ellipse/EllipseDetails.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.verdecken.ellipse; + +public class EllipseDetails { + + public void flexMethod(int ... werte) { + for (int wert : werte) { + // tu was + } + } + + public void verwender() { + flexMethod(3, 5, 7, 13, 21, 23); + } +} diff --git a/src/main/java/pr2/oo/verdecken/ellipse/EllipseDetailsEcht.java b/src/main/java/pr2/oo/verdecken/ellipse/EllipseDetailsEcht.java new file mode 100644 index 0000000..9fe8f7c --- /dev/null +++ b/src/main/java/pr2/oo/verdecken/ellipse/EllipseDetailsEcht.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.verdecken.ellipse; + +public class EllipseDetailsEcht { + + public void flexMethod(int[] werte) { + for (int wert : werte) { + // tu was + } + } + + public void verwender() { + flexMethod(new int[] { 3, 5, 7, 13, 21, 23 }); + } +} diff --git a/src/main/java/pr2/oo/verdecken/ueberladen/UeberladenUndPolymorphie.java b/src/main/java/pr2/oo/verdecken/ueberladen/UeberladenUndPolymorphie.java new file mode 100644 index 0000000..6d0f212 --- /dev/null +++ b/src/main/java/pr2/oo/verdecken/ueberladen/UeberladenUndPolymorphie.java @@ -0,0 +1,29 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.verdecken.ueberladen; + +public class UeberladenUndPolymorphie { + + public void method(A a) { + System.out.println("method(C a) gerufen"); + } + + public void method(B b) { + System.out.println("method(B b) gerufen"); + } + + public static void main(String[] args) { + UeberladenUndPolymorphie u = new UeberladenUndPolymorphie(); + + A a1 = new A(); + A a2 = new B(); + + u.method(a1); + u.method(a2); + } +} + +class A {} +class B extends A {} +class C extends B {} diff --git a/src/main/java/pr2/oo/vererbung/privat/Kampfechse.java b/src/main/java/pr2/oo/vererbung/privat/Kampfechse.java new file mode 100644 index 0000000..972a29b --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/privat/Kampfechse.java @@ -0,0 +1,9 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.vererbung.privat; + +public class Kampfechse extends Rennechse { + + public Kampfechse() { + super("Mike Tyson"); + } +} diff --git a/src/main/java/pr2/oo/vererbung/privat/Rennechse.java b/src/main/java/pr2/oo/vererbung/privat/Rennechse.java new file mode 100644 index 0000000..d7f5720 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/privat/Rennechse.java @@ -0,0 +1,23 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.vererbung.privat; + +public class Rennechse { + + private String name; + + public Rennechse(String name) { + this.name = name; + } + + private void adeln() { + name = "von " + name; + } + + public String getName() { + return name; + } + + public void guttenbergeisieren() { + adeln(); + } +} diff --git a/src/main/java/pr2/oo/vererbung/privat/Terrarium.java b/src/main/java/pr2/oo/vererbung/privat/Terrarium.java new file mode 100644 index 0000000..5c4cf0f --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/privat/Terrarium.java @@ -0,0 +1,21 @@ +/* (c) 2022 Thomas Smits */ +package pr2.oo.vererbung.privat; + +import java.lang.reflect.Field; + +public class Terrarium { + + @SuppressWarnings("rawtypes") + public static void main(String[] args) throws NoSuchFieldException, + SecurityException, IllegalArgumentException, IllegalAccessException { + Kampfechse k = new Kampfechse(); + Class ke = k.getClass(); + + Field f = Rennechse.class.getDeclaredField("name"); + f.setAccessible(true); + System.out.println(f.get(k)); + k.guttenbergeisieren(); + System.out.println(f.get(k)); + + } +} diff --git a/src/main/java/pr2/oo/vererbung/v1/Geschaeftsfuehrer.java b/src/main/java/pr2/oo/vererbung/v1/Geschaeftsfuehrer.java new file mode 100644 index 0000000..3c885dd --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v1/Geschaeftsfuehrer.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v1; + +public class Geschaeftsfuehrer extends Manager { + public boolean prokura = true; +} diff --git a/src/main/java/pr2/oo/vererbung/v1/GeschaeftsfuehrerBean.java b/src/main/java/pr2/oo/vererbung/v1/GeschaeftsfuehrerBean.java new file mode 100644 index 0000000..62b2172 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v1/GeschaeftsfuehrerBean.java @@ -0,0 +1,36 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v1; + +import java.util.Date; + +public class GeschaeftsfuehrerBean extends Manager { + + private boolean prokura = true; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public double getGehalt() { + return gehalt; + } + public void setGehalt(double gehalt) { + this.gehalt = gehalt; + } + public Date getGeburtsdatum() { + return geburtsdatum; + } + public void setGeburtsdatum(Date geburtsdatum) { + this.geburtsdatum = geburtsdatum; + } + public boolean isProkura() { + return prokura; + } + public void setProkura(boolean prokura) { + this.prokura = prokura; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v1/Manager.java b/src/main/java/pr2/oo/vererbung/v1/Manager.java new file mode 100644 index 0000000..075d9aa --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v1/Manager.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v1; + +public class Manager extends Mitarbeiter { + public String abteilung; +} diff --git a/src/main/java/pr2/oo/vererbung/v1/Mitarbeiter.java b/src/main/java/pr2/oo/vererbung/v1/Mitarbeiter.java new file mode 100644 index 0000000..01df7e6 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v1/Mitarbeiter.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v1; + +import java.util.Date; + +public class Mitarbeiter { + public String name; + public double gehalt; + public Date geburtsdatum; + + public String getDetails() { + return name + ", geb. am " + geburtsdatum + + " hat ein Gehalt von " + gehalt; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v1/MitarbeiterBean.java b/src/main/java/pr2/oo/vererbung/v1/MitarbeiterBean.java new file mode 100644 index 0000000..f483349 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v1/MitarbeiterBean.java @@ -0,0 +1,34 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v1; + +import java.util.Date; + +public class MitarbeiterBean { + private String name; + private double gehalt; + private Date geburtsdatum; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public double getGehalt() { + return gehalt; + } + public void setGehalt(double gehalt) { + this.gehalt = gehalt; + } + public Date getGeburtsdatum() { + return geburtsdatum; + } + public void setGeburtsdatum(Date geburtsdatum) { + this.geburtsdatum = geburtsdatum; + } + + + +} diff --git a/src/main/java/pr2/oo/vererbung/v2/Geschaeftsfuehrer.java b/src/main/java/pr2/oo/vererbung/v2/Geschaeftsfuehrer.java new file mode 100644 index 0000000..71df1c5 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v2/Geschaeftsfuehrer.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v2; + +public class Geschaeftsfuehrer extends Manager { + public boolean prokura = true; +} diff --git a/src/main/java/pr2/oo/vererbung/v2/Manager.java b/src/main/java/pr2/oo/vererbung/v2/Manager.java new file mode 100644 index 0000000..a1a02c1 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v2/Manager.java @@ -0,0 +1,18 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v2; + +import java.util.Date; + +public class Manager { + public String abteilung; + public String name; + public double gehalt; + public Date geburtsdatum; + + public String getDetails() { + return name + ", geb. am " + geburtsdatum + + " hat ein Gehalt von " + gehalt; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v2/Mitarbeiter.java b/src/main/java/pr2/oo/vererbung/v2/Mitarbeiter.java new file mode 100644 index 0000000..5c218fe --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v2/Mitarbeiter.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v2; + +import java.util.Date; + +public class Mitarbeiter { + public String name; + public double gehalt; + public Date geburtsdatum; + + public String getDetails() { + return name + ", geb. am " + geburtsdatum + + " hat ein Gehalt von " + gehalt; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v3/Geschaeftsfuehrer.java b/src/main/java/pr2/oo/vererbung/v3/Geschaeftsfuehrer.java new file mode 100644 index 0000000..2456d16 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v3/Geschaeftsfuehrer.java @@ -0,0 +1,15 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v3; + +public class Geschaeftsfuehrer extends Manager { + public boolean prokura = true; + + public String getDetails() { + return name + ", geb. am " + geburtsdatum + + " hat ein Gehalt von " + gehalt + + " und leitet die Abteilung " + abteilung + + " und hat Prokura " + prokura; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v3/Manager.java b/src/main/java/pr2/oo/vererbung/v3/Manager.java new file mode 100644 index 0000000..f1834db --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v3/Manager.java @@ -0,0 +1,14 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v3; + +public class Manager extends Mitarbeiter { + public String abteilung; + + public String getDetails() { + return name + ", geb. am " + geburtsdatum + + " hat ein Gehalt von " + gehalt + + " und leitet die Abteilung " + abteilung; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v3/Mitarbeiter.java b/src/main/java/pr2/oo/vererbung/v3/Mitarbeiter.java new file mode 100644 index 0000000..642c13f --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v3/Mitarbeiter.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v3; + +import java.util.Date; + +public class Mitarbeiter { + public String name; + public double gehalt; + public Date geburtsdatum; + + public String getDetails() { + return name + ", geb. am " + geburtsdatum + + " hat ein Gehalt von " + gehalt; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v4/Geschaeftsfuehrer.java b/src/main/java/pr2/oo/vererbung/v4/Geschaeftsfuehrer.java new file mode 100644 index 0000000..7f220a1 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v4/Geschaeftsfuehrer.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v4; + +public class Geschaeftsfuehrer extends Manager { + public boolean prokura = true; + + public String getDetails() { + return super.getDetails() + + " und hat Prokura " + prokura; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v4/Manager.java b/src/main/java/pr2/oo/vererbung/v4/Manager.java new file mode 100644 index 0000000..803434b --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v4/Manager.java @@ -0,0 +1,13 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v4; + +public class Manager extends Mitarbeiter { + public String abteilung; + + public String getDetails() { + return super.getDetails() + + " und leitet die Abteilung " + abteilung; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v4/Methodenaufruf.java b/src/main/java/pr2/oo/vererbung/v4/Methodenaufruf.java new file mode 100644 index 0000000..2772533 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v4/Methodenaufruf.java @@ -0,0 +1,144 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v4; + +import java.util.Date; + +public class Methodenaufruf { + + public void main() { + + { + Mitarbeiter mi = new Mitarbeiter(); + Manager ma = new Manager(); + + System.out.println(mi.getDetails()); + System.out.println(ma.getDetails()); + } + + { + Mitarbeiter mi = new Manager(); + System.out.println(mi.getDetails()); + } + + { + Mitarbeiter[] array = new Mitarbeiter[3]; + array[0] = new Mitarbeiter(); + array[1] = new Manager(); + array[2] = new Geschaeftsfuehrer(); + } + + { + Manager ma = new Manager(); + Mitarbeiter mi = new Mitarbeiter(); + + gehaltserhöhung(0.12, ma); + gehaltserhöhung(0.02, mi); + } + + { +// Manager ma = new Mitarbeiter(); + } + + { + Mitarbeiter mi = new Manager(); + + Manager ma = (Manager) mi; + ma.abteilung = "Buchhaltung"; + + ((Manager) mi).abteilung = "Buchhaltung"; + } + + { + Mitarbeiter mi = new Manager(); + if (mi instanceof Manager) {} + if (mi instanceof Mitarbeiter) {} + if (mi instanceof Geschaeftsfuehrer) {} + if (null instanceof Mitarbeiter) {} + + Object o = new Manager(); + o = new String(); + + Object[] os = new Object[2]; + os[0] = new Manager(); + os[1] = new Date(); + } + + Manager ma = new Manager(); + gehaltserhöhung(0.05d, ma); + } + + public void gehaltserhöhung(double prozente, Mitarbeiter mi) { + mi.gehalt *= 1.0 + prozente; + } + + public void automatischeErhöhung(Mitarbeiter mi) { + if (mi instanceof Geschaeftsfuehrer) { + gehaltserhöhung(0.10, mi); + } + else if (mi instanceof Manager) { + gehaltserhöhung(0.05, mi); + } + else { + gehaltserhöhung(0.0003, mi); + } + } + + public void gehaltserhöhung(Geschaeftsfuehrer mi) { + mi.gehalt = mi.gehalt * (1.0 + 0.2); + } + + public void gehaltserhöhung(Manager mi) { + mi.gehalt = mi.gehalt * (1.0 + 0.1); + } + + public void gehaltserhöhung(Mitarbeiter mi) { + mi.gehalt = mi.gehalt * (1.0 + 0.002); + } + + public int average(int a1, int a2) { return 0; } + public int average(int a1, int a2, int a3) { return 0; } + public int average(int a1, int a2, int a3, int a4) { return 0; } + + public void automatischeErhöhung2(Mitarbeiter mi) { + if (mi instanceof Geschaeftsfuehrer) { + + Geschaeftsfuehrer g = (Geschaeftsfuehrer) mi; + + if (g.prokura) { + mi.gehalt = mi.gehalt * (1 + 0.2); + } + else { + mi.gehalt = mi.gehalt * (1 + 0.1); + } + } + else if (mi instanceof Manager) { + mi.gehalt = mi.gehalt * (1 + 0.05); + } + else { + mi.gehalt = mi.gehalt * (1 + 0.002); + } + } + + public void automatischeErhöhung3(Mitarbeiter mi) { + + if (mi.getClass() == Geschaeftsfuehrer.class) { + + Geschaeftsfuehrer g = (Geschaeftsfuehrer) mi; + + if (g.prokura) { + mi.gehalt = mi.gehalt * (1 + 0.2); + } + else { + mi.gehalt = mi.gehalt * (1 + 0.1); + } + } + else if (mi.getClass() == Manager.class) { + mi.gehalt = mi.gehalt * (1 + 0.05); + } + else { + mi.gehalt = mi.gehalt * (1 + 0.002); + } + } +} diff --git a/src/main/java/pr2/oo/vererbung/v4/Mitarbeiter.java b/src/main/java/pr2/oo/vererbung/v4/Mitarbeiter.java new file mode 100644 index 0000000..e3f759e --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v4/Mitarbeiter.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v4; + +import java.util.Date; + +public class Mitarbeiter { + public String name; + public double gehalt; + public Date geboren; + + public String getDetails() { + return name + ", geb. am " + geboren + + " hat ein Gehalt von " + gehalt; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v5/Klasse.java b/src/main/java/pr2/oo/vererbung/v5/Klasse.java new file mode 100644 index 0000000..e189d58 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v5/Klasse.java @@ -0,0 +1,8 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v5; + +public class Klasse { + int i; +} diff --git a/src/main/java/pr2/oo/vererbung/v5/Klasse2.java b/src/main/java/pr2/oo/vererbung/v5/Klasse2.java new file mode 100644 index 0000000..b9e5c3b --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v5/Klasse2.java @@ -0,0 +1,14 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v5; + +public class Klasse2 extends Object { + + int i; + + public Klasse2() { + super(); + i = 0; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v5/Manager.java b/src/main/java/pr2/oo/vererbung/v5/Manager.java new file mode 100644 index 0000000..aa81ce9 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v5/Manager.java @@ -0,0 +1,20 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v5; + +import java.util.Date; + +public class Manager extends Mitarbeiter { + public String abteilung; + + public Manager(String name, double gehalt, Date geburtsdatum, String abteilung) { + super(name, gehalt, geburtsdatum); + this.abteilung = abteilung; + } + + public String getDetails() { + return super.getDetails() + + " und leitet die Abteilung " + abteilung; + } +} diff --git a/src/main/java/pr2/oo/vererbung/v5/Mitarbeiter.java b/src/main/java/pr2/oo/vererbung/v5/Mitarbeiter.java new file mode 100644 index 0000000..2591cc1 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/v5/Mitarbeiter.java @@ -0,0 +1,35 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.v5; + +import java.util.Date; + +public class Mitarbeiter { + public String name; + public double gehalt; + public Date geboren; + + public Mitarbeiter(String name, double gehalt, Date geboren) { + this.name = name; + this.gehalt = gehalt; + this.geboren = geboren; + } + + public Mitarbeiter(String name, double gehalt) { + this(name, gehalt, null); + } + + public Mitarbeiter(String name) { + this(name, 0.0d, null); + } + + public Mitarbeiter() { + + } + + public String getDetails() { + return name + ", geb. am " + geboren + + " hat ein Gehalt von " + gehalt; + } +} diff --git a/src/main/java/pr2/oo/vererbung/wasprotectedwirklichheisst/pack1/A.java b/src/main/java/pr2/oo/vererbung/wasprotectedwirklichheisst/pack1/A.java new file mode 100644 index 0000000..d4ebbde --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/wasprotectedwirklichheisst/pack1/A.java @@ -0,0 +1,12 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.wasprotectedwirklichheisst.pack1; + +public class A { + + protected int i; + + protected void method() { + } +} diff --git a/src/main/java/pr2/oo/vererbung/wasprotectedwirklichheisst/pack2/B.java b/src/main/java/pr2/oo/vererbung/wasprotectedwirklichheisst/pack2/B.java new file mode 100644 index 0000000..2ad8c35 --- /dev/null +++ b/src/main/java/pr2/oo/vererbung/wasprotectedwirklichheisst/pack2/B.java @@ -0,0 +1,17 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.vererbung.wasprotectedwirklichheisst.pack2; + +import pr2.oo.vererbung.wasprotectedwirklichheisst.pack1.A; + +public class B extends A { + + protected void method() { + i++; + } + + public void doIt(A a) { + // a.i++; + } +} diff --git a/src/main/java/pr2/oo/wrapper/AutoboxingDemo.java b/src/main/java/pr2/oo/wrapper/AutoboxingDemo.java new file mode 100644 index 0000000..4dfcd98 --- /dev/null +++ b/src/main/java/pr2/oo/wrapper/AutoboxingDemo.java @@ -0,0 +1,21 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.wrapper; + +public class AutoboxingDemo { + public static void main(String[] args) { + + Integer k = 5; + int j = k; + + Object o = true; + boolean b = Boolean.valueOf(true); + + Long l = 0L; + + for (int i = 0; i < Integer.MAX_VALUE; i++) { + l += i; + } + } +} diff --git a/src/main/java/pr2/oo/wrapper/BoxingFailure.java b/src/main/java/pr2/oo/wrapper/BoxingFailure.java new file mode 100644 index 0000000..9713e13 --- /dev/null +++ b/src/main/java/pr2/oo/wrapper/BoxingFailure.java @@ -0,0 +1,21 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.wrapper; + +public class BoxingFailure { + + public static boolean compare(Integer i1, Integer i2) { + return i1 == i2; + } + + public static void main(String[] args) { + int i1 = 10; + int i2 = 10; + System.out.println(i1 + " == " + i2 + " : " + compare(i1, i2)); + + i1 = 2000; + i2 = 2000; + System.out.println(i1 + " == " + i2 + " : " + compare(i1, i2)); + } +} diff --git a/src/main/java/pr2/oo/wrapper/WrapperDemo.java b/src/main/java/pr2/oo/wrapper/WrapperDemo.java new file mode 100644 index 0000000..c35a4d6 --- /dev/null +++ b/src/main/java/pr2/oo/wrapper/WrapperDemo.java @@ -0,0 +1,16 @@ +/* + * (c) 2009 Thomas Smits + */ +package pr2.oo.wrapper; + +public class WrapperDemo { + + public static void main(String[] args) { + int i = 5; + Integer i1 = Integer.valueOf(i); + int j = i1.intValue(); + + Integer i2 = Integer.valueOf("42"); + int i3 = Integer.parseInt("42"); + } +} diff --git a/src/main/java/pr2/oo1/konstruktor/hierarchie/A.java b/src/main/java/pr2/oo1/konstruktor/hierarchie/A.java index 22aff5b..8d86856 100644 --- a/src/main/java/pr2/oo1/konstruktor/hierarchie/A.java +++ b/src/main/java/pr2/oo1/konstruktor/hierarchie/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.konstruktor.hierarchie; +package pr2.oo.konstruktor.hierarchie; public class A extends Object { diff --git a/src/main/java/pr2/oo1/konstruktor/hierarchie/B.java b/src/main/java/pr2/oo1/konstruktor/hierarchie/B.java index b88062c..5d856fb 100644 --- a/src/main/java/pr2/oo1/konstruktor/hierarchie/B.java +++ b/src/main/java/pr2/oo1/konstruktor/hierarchie/B.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.konstruktor.hierarchie; +package pr2.oo.konstruktor.hierarchie; public class B extends A { diff --git a/src/main/java/pr2/oo1/konstruktor/probleme/A.java b/src/main/java/pr2/oo1/konstruktor/probleme/A.java index 6f54b52..d81331d 100644 --- a/src/main/java/pr2/oo1/konstruktor/probleme/A.java +++ b/src/main/java/pr2/oo1/konstruktor/probleme/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.konstruktor.probleme; +package pr2.oo.konstruktor.probleme; public class A { diff --git a/src/main/java/pr2/oo1/konstruktor/probleme/B.java b/src/main/java/pr2/oo1/konstruktor/probleme/B.java index 667001b..5889297 100644 --- a/src/main/java/pr2/oo1/konstruktor/probleme/B.java +++ b/src/main/java/pr2/oo1/konstruktor/probleme/B.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.konstruktor.probleme; +package pr2.oo.konstruktor.probleme; public class B extends A { diff --git a/src/main/java/pr2/oo1/object/clone/CloneDemo.java b/src/main/java/pr2/oo1/object/clone/CloneDemo.java index a04af66..1df7ded 100644 --- a/src/main/java/pr2/oo1/object/clone/CloneDemo.java +++ b/src/main/java/pr2/oo1/object/clone/CloneDemo.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.object.clone; +package pr2.oo.object.clone; public class CloneDemo { diff --git a/src/main/java/pr2/oo1/object/clone/Mitarbeiter.java b/src/main/java/pr2/oo1/object/clone/Mitarbeiter.java index 31a11fb..17b915d 100644 --- a/src/main/java/pr2/oo1/object/clone/Mitarbeiter.java +++ b/src/main/java/pr2/oo1/object/clone/Mitarbeiter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.object.clone; +package pr2.oo.object.clone; import java.util.Date; diff --git a/src/main/java/pr2/oo1/object/clone2/Main.java b/src/main/java/pr2/oo1/object/clone2/Main.java index 2819b80..7ecfe03 100644 --- a/src/main/java/pr2/oo1/object/clone2/Main.java +++ b/src/main/java/pr2/oo1/object/clone2/Main.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.oo1.object.clone2; +package pr2.oo.object.clone2; /** * diff --git a/src/main/java/pr2/oo1/object/clone2/Schaf.java b/src/main/java/pr2/oo1/object/clone2/Schaf.java index 65e4c88..85fc9d1 100644 --- a/src/main/java/pr2/oo1/object/clone2/Schaf.java +++ b/src/main/java/pr2/oo1/object/clone2/Schaf.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.oo1.object.clone2; +package pr2.oo.object.clone2; import java.util.Random; diff --git a/src/main/java/pr2/oo1/object/equals/EqualsDemo.java b/src/main/java/pr2/oo1/object/equals/EqualsDemo.java index 68d1ef4..3e209b8 100644 --- a/src/main/java/pr2/oo1/object/equals/EqualsDemo.java +++ b/src/main/java/pr2/oo1/object/equals/EqualsDemo.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.object.equals; +package pr2.oo.object.equals; public class EqualsDemo { diff --git a/src/main/java/pr2/oo1/object/equals/MeinDatum.java b/src/main/java/pr2/oo1/object/equals/MeinDatum.java index 943387a..40a9150 100644 --- a/src/main/java/pr2/oo1/object/equals/MeinDatum.java +++ b/src/main/java/pr2/oo1/object/equals/MeinDatum.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.object.equals; +package pr2.oo.object.equals; public class MeinDatum { int tag; diff --git a/src/main/java/pr2/oo1/object/equals/Mitarbeiter.java b/src/main/java/pr2/oo1/object/equals/Mitarbeiter.java index aa64ff8..3478c10 100644 --- a/src/main/java/pr2/oo1/object/equals/Mitarbeiter.java +++ b/src/main/java/pr2/oo1/object/equals/Mitarbeiter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.object.equals; +package pr2.oo.object.equals; import java.util.Date; diff --git a/src/main/java/pr2/oo1/object/intern/InternDemo.java b/src/main/java/pr2/oo1/object/intern/InternDemo.java index 2aa514b..e59cc3a 100644 --- a/src/main/java/pr2/oo1/object/intern/InternDemo.java +++ b/src/main/java/pr2/oo1/object/intern/InternDemo.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.object.intern; +package pr2.oo.object.intern; public class InternDemo { public static void main(String[] args) { diff --git a/src/main/java/pr2/oo1/quiz/binding/BindingQuiz.java b/src/main/java/pr2/oo1/quiz/binding/BindingQuiz.java index 15a9b54..f86b1aa 100644 --- a/src/main/java/pr2/oo1/quiz/binding/BindingQuiz.java +++ b/src/main/java/pr2/oo1/quiz/binding/BindingQuiz.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.binding; +package pr2.oo.quiz.binding; class A { } diff --git a/src/main/java/pr2/oo1/quiz/boxing/BoxingQuiz.java b/src/main/java/pr2/oo1/quiz/boxing/BoxingQuiz.java index 1f7eccb..0d1556a 100644 --- a/src/main/java/pr2/oo1/quiz/boxing/BoxingQuiz.java +++ b/src/main/java/pr2/oo1/quiz/boxing/BoxingQuiz.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.boxing; +package pr2.oo.quiz.boxing; public class BoxingQuiz { diff --git a/src/main/java/pr2/oo1/quiz/constructor/ConstructorQuiz.java b/src/main/java/pr2/oo1/quiz/constructor/ConstructorQuiz.java index 43a4b49..779619b 100644 --- a/src/main/java/pr2/oo1/quiz/constructor/ConstructorQuiz.java +++ b/src/main/java/pr2/oo1/quiz/constructor/ConstructorQuiz.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.constructor; +package pr2.oo.quiz.constructor; class A { public A() { System.out.println("A"); } diff --git a/src/main/java/pr2/oo1/quiz/constructor/NameHolder.java b/src/main/java/pr2/oo1/quiz/constructor/NameHolder.java index 0aff6fa..73b8f9b 100644 --- a/src/main/java/pr2/oo1/quiz/constructor/NameHolder.java +++ b/src/main/java/pr2/oo1/quiz/constructor/NameHolder.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.constructor; +package pr2.oo.quiz.constructor; public class NameHolder { diff --git a/src/main/java/pr2/oo1/quiz/equals/A.java b/src/main/java/pr2/oo1/quiz/equals/A.java index 1caa7a7..217ad93 100644 --- a/src/main/java/pr2/oo1/quiz/equals/A.java +++ b/src/main/java/pr2/oo1/quiz/equals/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.equals; +package pr2.oo.quiz.equals; public class A { diff --git a/src/main/java/pr2/oo1/quiz/equals2/A.java b/src/main/java/pr2/oo1/quiz/equals2/A.java index 2bd2fe7..dab8cad 100644 --- a/src/main/java/pr2/oo1/quiz/equals2/A.java +++ b/src/main/java/pr2/oo1/quiz/equals2/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.equals2; +package pr2.oo.quiz.equals2; public class A { diff --git a/src/main/java/pr2/oo1/quiz/polymorphie/Polymorphie.java b/src/main/java/pr2/oo1/quiz/polymorphie/Polymorphie.java index 09fc3cc..c8a6d3c 100644 --- a/src/main/java/pr2/oo1/quiz/polymorphie/Polymorphie.java +++ b/src/main/java/pr2/oo1/quiz/polymorphie/Polymorphie.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.polymorphie; +package pr2.oo.quiz.polymorphie; class A { public void f() { diff --git a/src/main/java/pr2/oo1/quiz/verdecken/A.java b/src/main/java/pr2/oo1/quiz/verdecken/A.java index a20772e..3f08de5 100644 --- a/src/main/java/pr2/oo1/quiz/verdecken/A.java +++ b/src/main/java/pr2/oo1/quiz/verdecken/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.verdecken; +package pr2.oo.quiz.verdecken; class A { diff --git a/src/main/java/pr2/oo1/quiz/verdecken/B.java b/src/main/java/pr2/oo1/quiz/verdecken/B.java index 846b78b..6aad39d 100644 --- a/src/main/java/pr2/oo1/quiz/verdecken/B.java +++ b/src/main/java/pr2/oo1/quiz/verdecken/B.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.verdecken; +package pr2.oo.quiz.verdecken; public class B extends A { diff --git a/src/main/java/pr2/oo1/quiz/vererbung/C.java b/src/main/java/pr2/oo1/quiz/vererbung/C.java index 67928aa..7da4e1d 100644 --- a/src/main/java/pr2/oo1/quiz/vererbung/C.java +++ b/src/main/java/pr2/oo1/quiz/vererbung/C.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.quiz.vererbung; +package pr2.oo.quiz.vererbung; class A { diff --git a/src/main/java/pr2/oo1/ueberschreiben/A.java b/src/main/java/pr2/oo1/ueberschreiben/A.java index cad21bc..c4e8042 100644 --- a/src/main/java/pr2/oo1/ueberschreiben/A.java +++ b/src/main/java/pr2/oo1/ueberschreiben/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.ueberschreiben; +package pr2.oo.ueberschreiben; class A { diff --git a/src/main/java/pr2/oo1/ueberschreiben/rueckgabetyp/A.java b/src/main/java/pr2/oo1/ueberschreiben/rueckgabetyp/A.java index 655a499..496e637 100644 --- a/src/main/java/pr2/oo1/ueberschreiben/rueckgabetyp/A.java +++ b/src/main/java/pr2/oo1/ueberschreiben/rueckgabetyp/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.ueberschreiben.rueckgabetyp; +package pr2.oo.ueberschreiben.rueckgabetyp; public class A { diff --git a/src/main/java/pr2/oo1/ueberschreiben/rueckgabetyp/B.java b/src/main/java/pr2/oo1/ueberschreiben/rueckgabetyp/B.java index faf30ba..e9739a7 100644 --- a/src/main/java/pr2/oo1/ueberschreiben/rueckgabetyp/B.java +++ b/src/main/java/pr2/oo1/ueberschreiben/rueckgabetyp/B.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.ueberschreiben.rueckgabetyp; +package pr2.oo.ueberschreiben.rueckgabetyp; public class B extends A { diff --git a/src/main/java/pr2/oo1/verdecken/A.java b/src/main/java/pr2/oo1/verdecken/A.java index de3b145..5e74341 100644 --- a/src/main/java/pr2/oo1/verdecken/A.java +++ b/src/main/java/pr2/oo1/verdecken/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.verdecken; +package pr2.oo.verdecken; public class A { public int i = 5; diff --git a/src/main/java/pr2/oo1/verdecken/B.java b/src/main/java/pr2/oo1/verdecken/B.java index 3d3eb30..337a437 100644 --- a/src/main/java/pr2/oo1/verdecken/B.java +++ b/src/main/java/pr2/oo1/verdecken/B.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.verdecken; +package pr2.oo.verdecken; public class B extends A { public String i = "Ein String in B"; diff --git a/src/main/java/pr2/oo1/verdecken/C.java b/src/main/java/pr2/oo1/verdecken/C.java index 536e03d..092cd4a 100644 --- a/src/main/java/pr2/oo1/verdecken/C.java +++ b/src/main/java/pr2/oo1/verdecken/C.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.verdecken; +package pr2.oo.verdecken; public class C { public int i = 1; diff --git a/src/main/java/pr2/oo1/verdecken/D.java b/src/main/java/pr2/oo1/verdecken/D.java index 740c2a2..a24e614 100644 --- a/src/main/java/pr2/oo1/verdecken/D.java +++ b/src/main/java/pr2/oo1/verdecken/D.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.verdecken; +package pr2.oo.verdecken; public class D extends C { private int i; // verdeckt i aus C mit private Sichtbarkeit diff --git a/src/main/java/pr2/oo1/verdecken/E.java b/src/main/java/pr2/oo1/verdecken/E.java index 7941404..e376d28 100644 --- a/src/main/java/pr2/oo1/verdecken/E.java +++ b/src/main/java/pr2/oo1/verdecken/E.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.verdecken; +package pr2.oo.verdecken; public class E extends D { // public void doIt() { diff --git a/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDemo.java b/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDemo.java index a0e937e..53de05d 100644 --- a/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDemo.java +++ b/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDemo.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.verdecken.ellipse; +package pr2.oo.verdecken.ellipse; public class EllipseDemo { diff --git a/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDetails.java b/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDetails.java index bc85df7..98314cd 100644 --- a/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDetails.java +++ b/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDetails.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.verdecken.ellipse; +package pr2.oo.verdecken.ellipse; public class EllipseDetails { diff --git a/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDetailsEcht.java b/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDetailsEcht.java index e66466b..9fe8f7c 100644 --- a/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDetailsEcht.java +++ b/src/main/java/pr2/oo1/verdecken/ellipse/EllipseDetailsEcht.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.verdecken.ellipse; +package pr2.oo.verdecken.ellipse; public class EllipseDetailsEcht { diff --git a/src/main/java/pr2/oo1/verdecken/ueberladen/UeberladenUndPolymorphie.java b/src/main/java/pr2/oo1/verdecken/ueberladen/UeberladenUndPolymorphie.java index 5f0a233..6d0f212 100644 --- a/src/main/java/pr2/oo1/verdecken/ueberladen/UeberladenUndPolymorphie.java +++ b/src/main/java/pr2/oo1/verdecken/ueberladen/UeberladenUndPolymorphie.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.verdecken.ueberladen; +package pr2.oo.verdecken.ueberladen; public class UeberladenUndPolymorphie { diff --git a/src/main/java/pr2/oo1/vererbung/privat/Kampfechse.java b/src/main/java/pr2/oo1/vererbung/privat/Kampfechse.java index 06adcbd..972a29b 100644 --- a/src/main/java/pr2/oo1/vererbung/privat/Kampfechse.java +++ b/src/main/java/pr2/oo1/vererbung/privat/Kampfechse.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.oo1.vererbung.privat; +package pr2.oo.vererbung.privat; public class Kampfechse extends Rennechse { diff --git a/src/main/java/pr2/oo1/vererbung/privat/Rennechse.java b/src/main/java/pr2/oo1/vererbung/privat/Rennechse.java index e9016be..d7f5720 100644 --- a/src/main/java/pr2/oo1/vererbung/privat/Rennechse.java +++ b/src/main/java/pr2/oo1/vererbung/privat/Rennechse.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.oo1.vererbung.privat; +package pr2.oo.vererbung.privat; public class Rennechse { diff --git a/src/main/java/pr2/oo1/vererbung/privat/Terrarium.java b/src/main/java/pr2/oo1/vererbung/privat/Terrarium.java index ef3fc22..5c4cf0f 100644 --- a/src/main/java/pr2/oo1/vererbung/privat/Terrarium.java +++ b/src/main/java/pr2/oo1/vererbung/privat/Terrarium.java @@ -1,5 +1,5 @@ /* (c) 2022 Thomas Smits */ -package pr2.oo1.vererbung.privat; +package pr2.oo.vererbung.privat; import java.lang.reflect.Field; diff --git a/src/main/java/pr2/oo1/vererbung/v1/Geschaeftsfuehrer.java b/src/main/java/pr2/oo1/vererbung/v1/Geschaeftsfuehrer.java index a0df0a5..3c885dd 100644 --- a/src/main/java/pr2/oo1/vererbung/v1/Geschaeftsfuehrer.java +++ b/src/main/java/pr2/oo1/vererbung/v1/Geschaeftsfuehrer.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v1; +package pr2.oo.vererbung.v1; public class Geschaeftsfuehrer extends Manager { public boolean prokura = true; diff --git a/src/main/java/pr2/oo1/vererbung/v1/GeschaeftsfuehrerBean.java b/src/main/java/pr2/oo1/vererbung/v1/GeschaeftsfuehrerBean.java index 5c350c0..62b2172 100644 --- a/src/main/java/pr2/oo1/vererbung/v1/GeschaeftsfuehrerBean.java +++ b/src/main/java/pr2/oo1/vererbung/v1/GeschaeftsfuehrerBean.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v1; +package pr2.oo.vererbung.v1; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/v1/Manager.java b/src/main/java/pr2/oo1/vererbung/v1/Manager.java index aa7119f..075d9aa 100644 --- a/src/main/java/pr2/oo1/vererbung/v1/Manager.java +++ b/src/main/java/pr2/oo1/vererbung/v1/Manager.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v1; +package pr2.oo.vererbung.v1; public class Manager extends Mitarbeiter { public String abteilung; diff --git a/src/main/java/pr2/oo1/vererbung/v1/Mitarbeiter.java b/src/main/java/pr2/oo1/vererbung/v1/Mitarbeiter.java index 96d82a9..01df7e6 100644 --- a/src/main/java/pr2/oo1/vererbung/v1/Mitarbeiter.java +++ b/src/main/java/pr2/oo1/vererbung/v1/Mitarbeiter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v1; +package pr2.oo.vererbung.v1; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/v1/MitarbeiterBean.java b/src/main/java/pr2/oo1/vererbung/v1/MitarbeiterBean.java index 0afddc4..f483349 100644 --- a/src/main/java/pr2/oo1/vererbung/v1/MitarbeiterBean.java +++ b/src/main/java/pr2/oo1/vererbung/v1/MitarbeiterBean.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v1; +package pr2.oo.vererbung.v1; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/v2/Geschaeftsfuehrer.java b/src/main/java/pr2/oo1/vererbung/v2/Geschaeftsfuehrer.java index 3ada69b..71df1c5 100644 --- a/src/main/java/pr2/oo1/vererbung/v2/Geschaeftsfuehrer.java +++ b/src/main/java/pr2/oo1/vererbung/v2/Geschaeftsfuehrer.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v2; +package pr2.oo.vererbung.v2; public class Geschaeftsfuehrer extends Manager { public boolean prokura = true; diff --git a/src/main/java/pr2/oo1/vererbung/v2/Manager.java b/src/main/java/pr2/oo1/vererbung/v2/Manager.java index 074c501..a1a02c1 100644 --- a/src/main/java/pr2/oo1/vererbung/v2/Manager.java +++ b/src/main/java/pr2/oo1/vererbung/v2/Manager.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v2; +package pr2.oo.vererbung.v2; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/v2/Mitarbeiter.java b/src/main/java/pr2/oo1/vererbung/v2/Mitarbeiter.java index 58ed4e5..5c218fe 100644 --- a/src/main/java/pr2/oo1/vererbung/v2/Mitarbeiter.java +++ b/src/main/java/pr2/oo1/vererbung/v2/Mitarbeiter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v2; +package pr2.oo.vererbung.v2; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/v3/Geschaeftsfuehrer.java b/src/main/java/pr2/oo1/vererbung/v3/Geschaeftsfuehrer.java index 8e291ab..2456d16 100644 --- a/src/main/java/pr2/oo1/vererbung/v3/Geschaeftsfuehrer.java +++ b/src/main/java/pr2/oo1/vererbung/v3/Geschaeftsfuehrer.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v3; +package pr2.oo.vererbung.v3; public class Geschaeftsfuehrer extends Manager { public boolean prokura = true; diff --git a/src/main/java/pr2/oo1/vererbung/v3/Manager.java b/src/main/java/pr2/oo1/vererbung/v3/Manager.java index 6a00a52..f1834db 100644 --- a/src/main/java/pr2/oo1/vererbung/v3/Manager.java +++ b/src/main/java/pr2/oo1/vererbung/v3/Manager.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v3; +package pr2.oo.vererbung.v3; public class Manager extends Mitarbeiter { public String abteilung; diff --git a/src/main/java/pr2/oo1/vererbung/v3/Mitarbeiter.java b/src/main/java/pr2/oo1/vererbung/v3/Mitarbeiter.java index d70017f..642c13f 100644 --- a/src/main/java/pr2/oo1/vererbung/v3/Mitarbeiter.java +++ b/src/main/java/pr2/oo1/vererbung/v3/Mitarbeiter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v3; +package pr2.oo.vererbung.v3; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/v4/Geschaeftsfuehrer.java b/src/main/java/pr2/oo1/vererbung/v4/Geschaeftsfuehrer.java index 977ca58..7f220a1 100644 --- a/src/main/java/pr2/oo1/vererbung/v4/Geschaeftsfuehrer.java +++ b/src/main/java/pr2/oo1/vererbung/v4/Geschaeftsfuehrer.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v4; +package pr2.oo.vererbung.v4; public class Geschaeftsfuehrer extends Manager { public boolean prokura = true; diff --git a/src/main/java/pr2/oo1/vererbung/v4/Manager.java b/src/main/java/pr2/oo1/vererbung/v4/Manager.java index 7b54752..803434b 100644 --- a/src/main/java/pr2/oo1/vererbung/v4/Manager.java +++ b/src/main/java/pr2/oo1/vererbung/v4/Manager.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v4; +package pr2.oo.vererbung.v4; public class Manager extends Mitarbeiter { public String abteilung; diff --git a/src/main/java/pr2/oo1/vererbung/v4/Methodenaufruf.java b/src/main/java/pr2/oo1/vererbung/v4/Methodenaufruf.java index 43b19ca..2772533 100644 --- a/src/main/java/pr2/oo1/vererbung/v4/Methodenaufruf.java +++ b/src/main/java/pr2/oo1/vererbung/v4/Methodenaufruf.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v4; +package pr2.oo.vererbung.v4; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/v4/Mitarbeiter.java b/src/main/java/pr2/oo1/vererbung/v4/Mitarbeiter.java index 85d1fed..e3f759e 100644 --- a/src/main/java/pr2/oo1/vererbung/v4/Mitarbeiter.java +++ b/src/main/java/pr2/oo1/vererbung/v4/Mitarbeiter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v4; +package pr2.oo.vererbung.v4; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/v5/Klasse.java b/src/main/java/pr2/oo1/vererbung/v5/Klasse.java index b5f36c2..e189d58 100644 --- a/src/main/java/pr2/oo1/vererbung/v5/Klasse.java +++ b/src/main/java/pr2/oo1/vererbung/v5/Klasse.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v5; +package pr2.oo.vererbung.v5; public class Klasse { int i; diff --git a/src/main/java/pr2/oo1/vererbung/v5/Klasse2.java b/src/main/java/pr2/oo1/vererbung/v5/Klasse2.java index 1060f38..b9e5c3b 100644 --- a/src/main/java/pr2/oo1/vererbung/v5/Klasse2.java +++ b/src/main/java/pr2/oo1/vererbung/v5/Klasse2.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v5; +package pr2.oo.vererbung.v5; public class Klasse2 extends Object { diff --git a/src/main/java/pr2/oo1/vererbung/v5/Manager.java b/src/main/java/pr2/oo1/vererbung/v5/Manager.java index a2b8fb9..aa81ce9 100644 --- a/src/main/java/pr2/oo1/vererbung/v5/Manager.java +++ b/src/main/java/pr2/oo1/vererbung/v5/Manager.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v5; +package pr2.oo.vererbung.v5; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/v5/Mitarbeiter.java b/src/main/java/pr2/oo1/vererbung/v5/Mitarbeiter.java index f3fb135..2591cc1 100644 --- a/src/main/java/pr2/oo1/vererbung/v5/Mitarbeiter.java +++ b/src/main/java/pr2/oo1/vererbung/v5/Mitarbeiter.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.v5; +package pr2.oo.vererbung.v5; import java.util.Date; diff --git a/src/main/java/pr2/oo1/vererbung/wasprotectedwirklichheisst/pack1/A.java b/src/main/java/pr2/oo1/vererbung/wasprotectedwirklichheisst/pack1/A.java index ed7c535..d4ebbde 100644 --- a/src/main/java/pr2/oo1/vererbung/wasprotectedwirklichheisst/pack1/A.java +++ b/src/main/java/pr2/oo1/vererbung/wasprotectedwirklichheisst/pack1/A.java @@ -1,7 +1,7 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.wasprotectedwirklichheisst.pack1; +package pr2.oo.vererbung.wasprotectedwirklichheisst.pack1; public class A { diff --git a/src/main/java/pr2/oo1/vererbung/wasprotectedwirklichheisst/pack2/B.java b/src/main/java/pr2/oo1/vererbung/wasprotectedwirklichheisst/pack2/B.java index e13bd0e..2ad8c35 100644 --- a/src/main/java/pr2/oo1/vererbung/wasprotectedwirklichheisst/pack2/B.java +++ b/src/main/java/pr2/oo1/vererbung/wasprotectedwirklichheisst/pack2/B.java @@ -1,9 +1,9 @@ /* * (c) 2009 Thomas Smits */ -package pr2.oo1.vererbung.wasprotectedwirklichheisst.pack2; +package pr2.oo.vererbung.wasprotectedwirklichheisst.pack2; -import pr2.oo1.vererbung.wasprotectedwirklichheisst.pack1.A; +import pr2.oo.vererbung.wasprotectedwirklichheisst.pack1.A; public class B extends A { diff --git a/src/main/java/pr2/oo2/interfaces/v4/Mathe2.java b/src/main/java/pr2/oo2/interfaces/v4/Mathe2.java index bdc0703..4f841c4 100644 --- a/src/main/java/pr2/oo2/interfaces/v4/Mathe2.java +++ b/src/main/java/pr2/oo2/interfaces/v4/Mathe2.java @@ -3,8 +3,6 @@ */ package pr2.oo2.interfaces.v4; -import static pr2.oo2.interfaces.v4.Konstanten.*; - public class Mathe2 { public double kreisFlaeche(double radius) {