diff --git a/Assignment_002/readme.md b/Assignment_002/readme.md index a6a914a..afdb5c2 100644 --- a/Assignment_002/readme.md +++ b/Assignment_002/readme.md @@ -1,6 +1,6 @@ # Labeled Break - + [Musterlösung](solution/) ## Lernziel diff --git a/Assignment_002/solution/readme.md b/Assignment_002/solution/readme.md new file mode 100644 index 0000000..6102863 --- /dev/null +++ b/Assignment_002/solution/readme.md @@ -0,0 +1,4 @@ +# Lösung: Labeled Break + + +[pr2.auffrischung.labeled_break](../../solutions/src/main/java/pr2/auffrischung/labeled_break) diff --git a/Assignment_003/readme.md b/Assignment_003/readme.md index d4c8278..9566be4 100644 --- a/Assignment_003/readme.md +++ b/Assignment_003/readme.md @@ -1,6 +1,6 @@ # Passwortbewertung - + [Musterlösung](solution/) ## Lernziel diff --git a/Assignment_003/solution/readme.md b/Assignment_003/solution/readme.md new file mode 100644 index 0000000..6b1732b --- /dev/null +++ b/Assignment_003/solution/readme.md @@ -0,0 +1,4 @@ +# Lösung: Passwortbewertung + + +[pr2.auffrischung.password](../../solutions/src/main/java/pr2/auffrischung/password) diff --git a/Assignment_004/readme.md b/Assignment_004/readme.md index fac2378..b3e3401 100644 --- a/Assignment_004/readme.md +++ b/Assignment_004/readme.md @@ -1,6 +1,6 @@ # printf mit Formatstring - + [Musterlösung](solution/) ## Lernziel diff --git a/Assignment_004/solution/readme.md b/Assignment_004/solution/readme.md new file mode 100644 index 0000000..bcda0d2 --- /dev/null +++ b/Assignment_004/solution/readme.md @@ -0,0 +1,4 @@ +# Lösung: printf mit Formatstring + + +[pr2.auffrischung.printf](../../solutions/src/main/java/pr2/auffrischung/printf) diff --git a/Assignment_005/readme.md b/Assignment_005/readme.md index ee3d9f1..a6e4663 100644 --- a/Assignment_005/readme.md +++ b/Assignment_005/readme.md @@ -1,6 +1,6 @@ # Maximum in einem Array suchen - + [Musterlösung](solution/) ## Lernziel diff --git a/Assignment_005/solution/readme.md b/Assignment_005/solution/readme.md new file mode 100644 index 0000000..9cd6fa7 --- /dev/null +++ b/Assignment_005/solution/readme.md @@ -0,0 +1,4 @@ +# Lösung: Maximum in einem Array suchen + + +[pr2.auffrischung.suchemax](../../solutions/src/main/java/pr2/auffrischung/suchemax) diff --git a/Assignment_006/readme.md b/Assignment_006/readme.md index a3daca9..0a75c26 100644 --- a/Assignment_006/readme.md +++ b/Assignment_006/readme.md @@ -1,6 +1,6 @@ # Taschenrechner - + [Musterlösung](solution/) ## Lernziel diff --git a/Assignment_006/solution/readme.md b/Assignment_006/solution/readme.md new file mode 100644 index 0000000..7e37500 --- /dev/null +++ b/Assignment_006/solution/readme.md @@ -0,0 +1,4 @@ +# Lösung: Taschenrechner + + +[pr2.auffrischung.taschenrechner](../../solutions/src/main/java/pr2/auffrischung/taschenrechner) diff --git a/Assignment_007/readme.md b/Assignment_007/readme.md index b744282..26822c1 100644 --- a/Assignment_007/readme.md +++ b/Assignment_007/readme.md @@ -1,6 +1,6 @@ # Quine - [Musterlösung](solution/) + ## Lernziel diff --git a/Assignment_007/solution/readme.md b/Assignment_007/solution/readme.md deleted file mode 100644 index 4ac7e2a..0000000 --- a/Assignment_007/solution/readme.md +++ /dev/null @@ -1,5 +0,0 @@ -# Lösung: Quine - -Musterlösung: - -[pr2.auffrischung.quine](../../solutions/src/main/java/pr2/auffrischung/quine/) diff --git a/readme.md b/readme.md index 5a99a15..3edcafc 100644 --- a/readme.md +++ b/readme.md @@ -11,12 +11,12 @@ Hinweise zur nötigen Softwareausstattung finden Sie [hier](help/softwareausstat | # | Ausgabe | Thema | Musterlösung | |----|---------------------------------------------------------------------------------------------|----------------|----------------| | 1. | n/a | [String in Großbuchstaben umwandeln](Assignment_001/readme.md) | [✅](Assignment_001/solution/readme.md) | -| 2. | n/a | [Labeled Break](Assignment_002/readme.md) | | -| 3. | n/a | [Passwortbewertung](Assignment_003/readme.md) | | -| 4. | n/a | [printf mit Formatstring](Assignment_004/readme.md) | | -| 5. | n/a | [Maximum in einem Array suchen](Assignment_005/readme.md) | | -| 6. | n/a | [Taschenrechner](Assignment_006/readme.md) | | -| 7. | n/a | [Quine](Assignment_007/readme.md) | [✅](Assignment_007/solution/readme.md) | +| 2. | n/a | [Labeled Break](Assignment_002/readme.md) | [✅](Assignment_002/solution/readme.md) | +| 3. | n/a | [Passwortbewertung](Assignment_003/readme.md) | [✅](Assignment_003/solution/readme.md) | +| 4. | n/a | [printf mit Formatstring](Assignment_004/readme.md) | [✅](Assignment_004/solution/readme.md) | +| 5. | n/a | [Maximum in einem Array suchen](Assignment_005/readme.md) | [✅](Assignment_005/solution/readme.md) | +| 6. | n/a | [Taschenrechner](Assignment_006/readme.md) | [✅](Assignment_006/solution/readme.md) | +| 7. | n/a | [Quine](Assignment_007/readme.md) | | | 8. | n/a | [Java-Coding-Standard anwenden](Assignment_008/readme.md) | | | 9. | n/a | [JavaDoc schreiben](Assignment_009/readme.md) | | | 10. | n/a | [Klasse mit JUnit testen](Assignment_010/readme.md) | | diff --git a/solutions/src/main/java/pr2/auffrischung/labeled_break/ArraySucher.java b/solutions/src/main/java/pr2/auffrischung/labeled_break/ArraySucher.java new file mode 100644 index 0000000..82e1359 --- /dev/null +++ b/solutions/src/main/java/pr2/auffrischung/labeled_break/ArraySucher.java @@ -0,0 +1,27 @@ +package pr2.auffrischung.labeled_break; + +public class ArraySucher { + + /** + * Sucht das erste Element, dass nicht 0 ist. + * + * @param array das Array in dem gesucht werden soll + * @return {@code true}, wenn ein Element gefunden wird, + * andernfalls {@code false}. + */ + public boolean suche(int[][] array) { + boolean found = false; + + outer: + for (int[] is : array) { + for (int i : is) { + if (i != 0) { + found = true; + break outer; + } + } + } + + return found; + } +} diff --git a/solutions/src/main/java/pr2/auffrischung/password/PasswortChecker.java b/solutions/src/main/java/pr2/auffrischung/password/PasswortChecker.java new file mode 100644 index 0000000..147b8be --- /dev/null +++ b/solutions/src/main/java/pr2/auffrischung/password/PasswortChecker.java @@ -0,0 +1,53 @@ +package pr2.auffrischung.password; + +public class PasswortChecker { + + private static final char[] NUMBERS = "1234567890".toCharArray(); + private static final char[] LOWERCASE + = "abcdefghijklmnopqrstuvwxyz".toCharArray(); + private static final char[] UPPERCASE + = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray(); + private static final char[] SPECIAL_CHARS = "!%()\"".toCharArray(); + + private static boolean contains(String string, char[] chars) { + for (char c : chars) { + if (string.indexOf(c) >= 0) { + return true; + } + } + return false; + } + + public static int checkPassword(String password) { + int points = 0; + + if (password.length() >= 8) { + points++; + } + + if (contains(password, NUMBERS) + && (contains(password, LOWERCASE) + || contains(password, UPPERCASE))) { + points++; + } + + if (contains(password, SPECIAL_CHARS)) { + points++; + } + + if (contains(password, LOWERCASE) && contains(password, UPPERCASE)) { + points++; + } + + return points; + } + + public static void main(String[] args) { + System.out.println(checkPassword("mutti")); + System.out.println(checkPassword("Mutti")); + System.out.println(checkPassword("mutti123")); + System.out.println(checkPassword("Mutti123")); + System.out.println(checkPassword("Mutti123!%")); + System.out.println(checkPassword("1234")); + } +} diff --git a/solutions/src/main/java/pr2/auffrischung/printf/DoubleFormatter.java b/solutions/src/main/java/pr2/auffrischung/printf/DoubleFormatter.java new file mode 100644 index 0000000..788b1a6 --- /dev/null +++ b/solutions/src/main/java/pr2/auffrischung/printf/DoubleFormatter.java @@ -0,0 +1,18 @@ +package pr2.auffrischung.printf; + +public class DoubleFormatter { + + public static void printDouble(double d) { + System.out.printf("%.3f%n", d); + } + + public static void main(String[] args) { + printDouble(1.0); + printDouble(10.1); + printDouble(2.01); + printDouble(2.001); + printDouble(2.0001); + printDouble(2.0004); + printDouble(2.0005); + } +} diff --git a/solutions/src/main/java/pr2/auffrischung/quine/Quine.java b/solutions/src/main/java/pr2/auffrischung/quine/Quine.java deleted file mode 100644 index 6ee66d9..0000000 --- a/solutions/src/main/java/pr2/auffrischung/quine/Quine.java +++ /dev/null @@ -1,19 +0,0 @@ - -package pr2.auffrischung.quine; - -public class Quine { - - private static final String DATA = "package pr2.auffrischung.quine;%n%n" - + "public class Quine {%n%n" - + " private static final String DATA = \"%s\";%n%n" - + " public static void main(String[] args) {%n" - + " System.out.printf(data, %n" - + " DATA.replace(\"\\\\\", \"\\\\\\\\\")%n" - + " .replace(\"\\\"\", \"\\\\\\\"\"));%n }%n}"; - - public static void main(String[] args) { - System.out.printf(DATA, - DATA.replace("\\", "\\\\") - .replace("\"", "\\\"")); - } -} diff --git a/solutions/src/main/java/pr2/auffrischung/suchemax/GroessteZahl.java b/solutions/src/main/java/pr2/auffrischung/suchemax/GroessteZahl.java new file mode 100644 index 0000000..92f89b7 --- /dev/null +++ b/solutions/src/main/java/pr2/auffrischung/suchemax/GroessteZahl.java @@ -0,0 +1,21 @@ +package pr2.auffrischung.suchemax; + +public class GroessteZahl { + + public int sucheMax(int[] zahlen) { + int max = Integer.MIN_VALUE; + + for (int zahl : zahlen) { + max = Math.max(max, zahl); + } + + return max; + } + + public static void main(String[] args) { + GroessteZahl g = new GroessteZahl(); + System.out.println(g.sucheMax(new int[] {1, 5, 8, 2, 0})); + System.out.println(g.sucheMax(new int[] {-1, -5, -8, -2, -20})); + System.out.println(g.sucheMax(new int[] {10000, -10000, 1, 2, 33})); + } +} diff --git a/solutions/src/main/java/pr2/auffrischung/taschenrechner/Taschenrechner.java b/solutions/src/main/java/pr2/auffrischung/taschenrechner/Taschenrechner.java new file mode 100644 index 0000000..ecba9e2 --- /dev/null +++ b/solutions/src/main/java/pr2/auffrischung/taschenrechner/Taschenrechner.java @@ -0,0 +1,25 @@ +package pr2.auffrischung.taschenrechner; + +public class Taschenrechner { + + public double rechne(double o1, char op, double o2) { + return switch (op) { + case '+' -> o1 + o2; + case '-' -> o1 - o2; + case '*' -> o1 * o2; + case '/' -> o1 / o2; + case '^' -> Math.pow(o1, o2); + default -> Double.NaN; + }; +// return 0.0; + } + + public static void main(String[] args) { + Taschenrechner t = new Taschenrechner(); + System.out.println(t.rechne(1, '+', 2)); + System.out.println(t.rechne(1, '-', 2)); + System.out.println(t.rechne(2, '*', 2)); + System.out.println(t.rechne(4, '/', 2)); + System.out.println(t.rechne(2, '^', 32)); + } +}