added blatt 4 and restructured

This commit is contained in:
Sven Vogel 2023-04-26 20:36:43 +02:00
parent 32ba8f6958
commit 083c15bf8b
27 changed files with 697 additions and 195 deletions

View File

@ -2,13 +2,10 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/GgtUndKgv/GgtUndKgv.iml" filepath="$PROJECT_DIR$/GgtUndKgv/GgtUndKgv.iml" /> <module fileurl="file://$PROJECT_DIR$/AufgabenBlatt3/AufgabenBlatt3.iml" filepath="$PROJECT_DIR$/AufgabenBlatt3/AufgabenBlatt3.iml" />
<module fileurl="file://$PROJECT_DIR$/AufgabenBlatt4/AufgabenBlatt4.iml" filepath="$PROJECT_DIR$/AufgabenBlatt4/AufgabenBlatt4.iml" />
<module fileurl="file://$PROJECT_DIR$/GregorianischerKalender/GregorianischerKalender.iml" filepath="$PROJECT_DIR$/GregorianischerKalender/GregorianischerKalender.iml" /> <module fileurl="file://$PROJECT_DIR$/GregorianischerKalender/GregorianischerKalender.iml" filepath="$PROJECT_DIR$/GregorianischerKalender/GregorianischerKalender.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/Java-Programming.iml" filepath="$PROJECT_DIR$/.idea/Java-Programming.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/Java-Programming.iml" filepath="$PROJECT_DIR$/.idea/Java-Programming.iml" />
<module fileurl="file://$PROJECT_DIR$/Konto/Konto.iml" filepath="$PROJECT_DIR$/Konto/Konto.iml" />
<module fileurl="file://$PROJECT_DIR$/Maximum/Maximum.iml" filepath="$PROJECT_DIR$/Maximum/Maximum.iml" />
<module fileurl="file://$PROJECT_DIR$/Verzinsung/Verzinsung.iml" filepath="$PROJECT_DIR$/Verzinsung/Verzinsung.iml" />
<module fileurl="file://$PROJECT_DIR$/Zaubern/Zaubern.iml" filepath="$PROJECT_DIR$/Zaubern/Zaubern.iml" />
</modules> </modules>
</component> </component>
</project> </project>

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -16,7 +16,7 @@
* Licensed under the GPLv2 License, Version 2.0 (the "License"); * Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel * Copyright (c) Sven Vogel
*/ */
public class Main { public class Aufgabe3 {
/** /**
* compute the maximum of a and b * compute the maximum of a and b

View File

@ -0,0 +1,44 @@
import org.junit.Test;
import static junit.framework.TestCase.*;
/**
* Generic test class for implementing and testing
* a simple boolean majority function
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Aufgabe4 {
/**
* Returns true if at least one of the parameters is true
* @param a
* @param b
* @param c
* @return the bitwise OR of the parameters
*/
private static boolean majority(boolean a, boolean b, boolean c) {
return a || b || c;
}
@Test
public void test() {
assertTrue(majority(true, true, true));
assertTrue(majority(true, false, true));
assertTrue(majority(true, true, false));
assertTrue(majority(true, false, false));
assertFalse(majority(false, false, false));
}
}

View File

@ -21,7 +21,7 @@ import java.util.Random;
* NOTE: following code mostly copied from the teacher, * NOTE: following code mostly copied from the teacher,
* expect no comments or functionality * expect no comments or functionality
*/ */
public class Main { public class Aufgabe6 {
enum Zauberspruch { enum Zauberspruch {
ENTWAFFNUNGSZAUBER, ENTWAFFNUNGSZAUBER,

View File

@ -16,7 +16,7 @@
* Licensed under the GPLv2 License, Version 2.0 (the "License"); * Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel * Copyright (c) Sven Vogel
*/ */
public class Konto { public class Aufgabe7 {
private double guthaben; private double guthaben;
@ -58,7 +58,7 @@ public class Konto {
} }
public static void main(String[] args) { public static void main(String[] args) {
var konto = new Konto(); var konto = new Aufgabe7();
konto.einzahlen(134); konto.einzahlen(134);
konto.einzahlen(0.345); konto.einzahlen(0.345);

View File

@ -18,7 +18,7 @@ import javax.swing.*;
* Licensed under the GPLv2 License, Version 2.0 (the "License"); * Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel * Copyright (c) Sven Vogel
*/ */
public class Main { public class Aufgabe8 {
/** /**
* calculate the linear zins over a span of years * calculate the linear zins over a span of years

View File

@ -1,48 +1,7 @@
package aufgabe5;
import javax.swing.*; import javax.swing.*;
/**
* Generic test class for implementing
* ggt and kgv
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
class Rechnen {
/**
* compute the greatest common divisor of x and y
* @param x the first number to compute the greatest common divisor of
* @param y the second number to compute the greatest common divisor of
* @return the greatest common divisor of x and y
*/
public static int ggt(int x, int y) {
if (x == 0)
return y;
return ggt(x, y % x);
}
/**
* compute the smallest common multiple of x and y
* @param x the first number to compute the smallest common multiple of
* @param y the second number to compute the smallest common multiple of
* @return the smallest common multiple of x and y
*/
public static int kgv(int x, int y) {
return (x * y) / ggt(x, y);
}
}
/** /**
* Generic test class for testing * Generic test class for testing
* kgv and ggt * kgv and ggt

View File

@ -0,0 +1,44 @@
package aufgabe5;
/**
* Generic test class for implementing
* ggt and kgv
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Rechnen {
/**
* compute the greatest common divisor of x and y
* @param x the first number to compute the greatest common divisor of
* @param y the second number to compute the greatest common divisor of
* @return the greatest common divisor of x and y
*/
public static int ggt(int x, int y) {
if (y == 0)
return x;
return ggt(y, y % x);
}
/**
* compute the smallest common multiple of x and y
* @param x the first number to compute the smallest common multiple of
* @param y the second number to compute the smallest common multiple of
* @return the smallest common multiple of x and y
*/
public static int kgv(int x, int y) {
return (x * y) / ggt(x, y);
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -0,0 +1,40 @@
import org.junit.Test;
/**
* Generic test class for implementing and testing repeating strings
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Aufgabe2 {
/**
* Repeat the supplied character by a given number
* @param symbol the character to repeat
* @param number number of repetitions
* @return the repeated characters as string
*/
private static String repeat(char symbol, int number) {
if (number == 0) {
return String.valueOf(symbol);
}
return symbol + repeat(symbol, number - 1);
}
@Test
public void test() {
var result = repeat('a', 78);
System.out.println(result);
}
}

View File

@ -0,0 +1,58 @@
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
/**
* Generic test class for implementing and testing fibonacci algorithms
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Aufgabe3 {
/**
* calculate the fibonacci value of any given element by recursion
* @param x the index of the fibonacci sequence
* @return the fibonacci value for the given index
*/
private static int fibonacciRecursive(int x) {
return x < 2 ? x : fibonacciRecursive(x - 1) + fibonacciRecursive(x - 2);
}
/**
* calculate the fibonacci value of any given element by iteration
* @param x the index of the fibonacci sequence
* @return the fibonacci value for the given index
*/
private static int fibonacciIterative(int x) {
int sum = 0;
int sum2 = 1;
for (int y = 0; y < (x - 1); y++) {
int t = sum;
sum = sum2;
sum2 = t + sum;
}
return sum2;
}
@Test
public void test() {
System.out.println("recursive: " + fibonacciRecursive(7));
System.out.println("iterative: " + fibonacciIterative(7));
assertEquals(fibonacciRecursive(7), fibonacciIterative(7));
assertEquals(fibonacciRecursive(68), fibonacciIterative(68));
assertEquals(fibonacciRecursive(13), fibonacciIterative(13));
}
}

View File

@ -0,0 +1,44 @@
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
/**
* Generic test class for implementing and testing an algorithm to reverse strings
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Aufgabe4 {
/**
* Dreht ein übergebenes Wort um und gibt das Ergebnis
* als einen neuen String zurück.
* Beispiel: Bei dem Argument "katze" ist die Rückgabe "eztak".
*
* @pre wort != null und mindestens 1 Zeichen lang.
* @param wort Wort, das umgedreht werden soll.
* @return Umgedrehtes Wort.
*/
public static String dreheWortUm(String wort) {
if (wort.length() < 2) {
return wort;
}
return dreheWortUm(wort.substring(1)) + wort.charAt(0);
}
@Test
public void test() {
assertEquals(dreheWortUm("abcdefghijklmnopqrstuvwxyz"), "zyxwvutsrqponmlkjihgfedcba");
}
}

View File

@ -0,0 +1,66 @@
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
/**
* Generic test class for implementing and testing a sequence in recursive and iterative form
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Aufgabe5 {
/**
* Calculate some recursive sequence
* @param n the number to calculate the sequence of
* @return the value for the given number of the sequence
*/
private static int recursiveFunction(int n) {
if (n <= 0) {
return 1;
} else if (n == 1) {
return 2;
}
return 4 * recursiveFunction(n - 2);
}
/**
* Calculate some iterative sequence
* @param n the number to calculate the sequence of
* @return the value for the given number of the sequence
*/
private static int iterativeFunction(int n) {
if (n <= 0) {
return 1;
} else if (n == 1) {
return 2;
}
int sum = 1;
for (int i = 2; i < n; i += 2) {
sum *= 4;
}
return sum;
}
@Test
public void test() {
assertEquals(recursiveFunction(0), 1);
assertEquals(recursiveFunction(1), 2);
System.out.println("greater than 1: " + recursiveFunction(12));
assertEquals(recursiveFunction(67), iterativeFunction(67));
}
}

View File

@ -0,0 +1,57 @@
import java.util.Scanner;
/**
* Generic test class for implementing and testing listing all permutations of a given number of characters
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Aufgabe6 {
/**
* Print all permutations of every character from the beginning of the alphabet to the N-th character
* @param n the index of the highest character to use
*/
private static void printPermutations(int n) {
if (n < 0 || n > 26) {
throw new IllegalArgumentException("N must be between 0 and 26");
}
final var LOOKUP = "abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < n; i++) {
var builder = new StringBuilder();
// rotate characters
for (int k = 0; k < n; k++) {
var idx = (i + k) % n;
builder.append(LOOKUP.charAt(idx));
}
System.out.println(builder);
// reverse rotated characters
builder.reverse();
System.out.println(builder);
}
}
public static void main(String[] args) {
try(var scanner = new Scanner(System.in)) {
var n = scanner.nextInt(10);
printPermutations(n);
}
}
}

View File

@ -0,0 +1,169 @@
import org.junit.Test;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
/**
* Generic test class for implementing and testing palindrome detection
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Aufgabe7 {
/**
* Tests whether the supplied string is a palindrome or not using iterations
*
* @implNote returns true if the supplied string is smaller than 2 or blank
* @param text the string to test
* @return true if the supplied string is a palindrome, false otherwise
*/
private static boolean isPalindrome(String text) {
if (text.isBlank() || text.length() < 2)
return true;
for (int i = 0; i < text.length() / 2; i++) {
if (text.charAt(i) != text.charAt(text.length() - i - 1))
return false;
}
return true;
}
/**
* Tests whether the supplied string is a palindrome or not using recursion
*
* @implNote returns true if the supplied string is smaller than 2 or blank
* @param text the string to test
* @return true if the supplied string is a palindrome, false otherwise
*/
private static boolean isPalindromeRecursive(String text) {
if (text.isBlank() || text.length() < 2)
return true;
if (text.charAt(0) != text.charAt(text.length() - 1))
return false;
return isPalindromeRecursive(text.substring(1, text.length() - 1));
}
/**
* Tests whether the supplied string is a palindrome or not by iteration
* also ignores case
*
* @implNote returns true if the supplied string is smaller than 2 or blank
* @param text the string to test
* @return true if the supplied string is a palindrome, false otherwise
*/
private static boolean isPalindromeIgnoreCase(String text) {
if (text.isBlank() || text.length() < 2)
return true;
var lowerCase = text.toLowerCase();
for (int i = 0; i < text.length() / 2; i++) {
if (lowerCase.charAt(i) != lowerCase.charAt(text.length() - i - 1))
return false;
}
return true;
}
/**
* Test iterative palindrome detection
*/
@Test
public void testLowercaseIterative() {
var PALINDROMES = new String[]{
"otto",
"121",
"regallager",
"reliefpfeiler"
};
// palindromes
for (var palindrome : PALINDROMES) {
assertTrue(isPalindrome(palindrome));
}
var NO_PALINDROMES = new String[]{
"abcdefghijklmnopqrstuvwxyz",
"sven vogel",
"koeffizient"
};
// no palindromes
for (var noPalindrome : NO_PALINDROMES) {
assertFalse(isPalindrome(noPalindrome));
}
}
/**
* Test recursive palindrome detection
*/
@Test
public void testLowercaseRecursive() {
var PALINDROMES = new String[]{
"otto",
"121",
"regallager",
"reliefpfeiler"
};
// palindromes
for (var palindrome : PALINDROMES) {
assertTrue(isPalindromeRecursive(palindrome));
}
var NO_PALINDROMES = new String[]{
"abcdefghijklmnopqrstuvwxyz",
"sven vogel",
"koeffizient"
};
// no palindromes
for (var noPalindrome : NO_PALINDROMES) {
assertFalse(isPalindromeRecursive(noPalindrome));
}
}
/**
* Test iterative palindrome detection with ignore case
*/
@Test
public void testIgnoreCaseIterative() {
var PALINDROMES = new String[]{
"OtTo",
"121",
"ReGaLlAgeR",
"reLiEfPfeIler"
};
// palindromes
for (var palindrome : PALINDROMES) {
assertTrue(isPalindromeIgnoreCase(palindrome));
}
var NO_PALINDROMES = new String[]{
"AbcdeFghijKlmnOpqRstUvwxyz",
"sVeN vOgeL",
"kOefFiZiEnt"
};
// no palindromes
for (var noPalindrome : NO_PALINDROMES) {
assertFalse(isPalindromeIgnoreCase(noPalindrome));
}
}
}

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

29
Maximum/.gitignore vendored
View File

@ -1,29 +0,0 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

29
Verzinsung/.gitignore vendored
View File

@ -1,29 +0,0 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

29
Zaubern/.gitignore vendored
View File

@ -1,29 +0,0 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>