From 32ba8f695818900e015baf65dcdcfd53f5d712b5 Mon Sep 17 00:00:00 2001 From: teridax Date: Fri, 21 Apr 2023 12:39:35 +0200 Subject: [PATCH] updated license information --- .idea/modules.xml | 2 +- GgtUndKgv/src/Main.java | 44 ++++++++++++++++- .../.gitignore | 0 .../GregorianischerKalender.iml | 0 GregorianischerKalender/src/Main.java | 38 ++++++++++++++ GreogorianischerKalender/src/Main.java | 14 ------ Konto/src/Konto.java | 45 ++++++++++++++--- Maximum/src/Main.java | 45 +++++++++++++++-- README.md | 6 +++ Verzinsung/src/Main.java | 49 ++++++++++++++++++- Zaubern/src/Main.java | 21 ++++++++ 11 files changed, 237 insertions(+), 27 deletions(-) rename {GreogorianischerKalender => GregorianischerKalender}/.gitignore (100%) rename GreogorianischerKalender/GreogorianischerKalender.iml => GregorianischerKalender/GregorianischerKalender.iml (100%) create mode 100644 GregorianischerKalender/src/Main.java delete mode 100644 GreogorianischerKalender/src/Main.java diff --git a/.idea/modules.xml b/.idea/modules.xml index d21f443..2ff033c 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,7 +3,7 @@ - + diff --git a/GgtUndKgv/src/Main.java b/GgtUndKgv/src/Main.java index a515445..83a3eda 100644 --- a/GgtUndKgv/src/Main.java +++ b/GgtUndKgv/src/Main.java @@ -1,18 +1,58 @@ 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 { - static int ggt(int x, int y) { + /** + * 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); } - static int kgv(int x, int y) { + /** + * 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 + * kgv and ggt + *

+ * Licensed under the GPLv2 License, Version 2.0 (the "License"); + * Copyright (c) Sven Vogel + *

+ * NOTE: following code mostly copied from the teacher, + * expect no comments or functionality + */ public class Main { public static void main(String[] args) { diff --git a/GreogorianischerKalender/.gitignore b/GregorianischerKalender/.gitignore similarity index 100% rename from GreogorianischerKalender/.gitignore rename to GregorianischerKalender/.gitignore diff --git a/GreogorianischerKalender/GreogorianischerKalender.iml b/GregorianischerKalender/GregorianischerKalender.iml similarity index 100% rename from GreogorianischerKalender/GreogorianischerKalender.iml rename to GregorianischerKalender/GregorianischerKalender.iml diff --git a/GregorianischerKalender/src/Main.java b/GregorianischerKalender/src/Main.java new file mode 100644 index 0000000..20e4fb9 --- /dev/null +++ b/GregorianischerKalender/src/Main.java @@ -0,0 +1,38 @@ +/** + * Generic test class for implementing and testing + * for leap years according to the gregorian calendar + * _ _ _ _ + * __ ___ __(_) |_| |_ ___ _ __ | |__ _ _ + * \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | | + * \ V V /| | | | |_| || __/ | | | | |_) | |_| | + * \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, | + * |___/ + * ____ __ __ _ + * / ___|_ _____ _ __ \ \ / /__ __ _ ___| | + * \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ | + * ___) \ V / __/ | | | \ V / (_) | (_| | __/ | + * |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_| + * |___/ + * Licensed under the GPLv2 License, Version 2.0 (the "License"); + * Copyright (c) Sven Vogel + */ +public class Main { + + /** + * Test whether the supplied year is a leap year according to the gregorian calendar + * @apiNote also works with negative numbers + * @param year the year to test + * @return if the year is a leap year + */ + private static boolean isLeapYearGregorianCalendar(int year) { + int decade = year / 10; + return decade % 4 != 0; + } + + public static void main(String[] args) { + System.out.println("is leap year: 1904: " + isLeapYearGregorianCalendar(1904)); + System.out.println("is leap year: 1003: " + isLeapYearGregorianCalendar(1003)); + System.out.println("is leap year: 1422: " + isLeapYearGregorianCalendar(1422)); + System.out.println("is leap year: 2022: " + isLeapYearGregorianCalendar(2022)); + } +} \ No newline at end of file diff --git a/GreogorianischerKalender/src/Main.java b/GreogorianischerKalender/src/Main.java deleted file mode 100644 index ba3d3ad..0000000 --- a/GreogorianischerKalender/src/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -public class Main { - - private static boolean isLeapYearGregorianCalendar(int year) { - int decade = year / 10; - return decade % 4 != 0; - } - - public static void main(String[] args) { - System.out.println("is leap year: 1904: " + isLeapYearGregorianCalendar(1904)); - System.out.println("is leap year: 1003: " + isLeapYearGregorianCalendar(1003)); - System.out.println("is leap year: 1422: " + isLeapYearGregorianCalendar(1422)); - System.out.println("is leap year: 2022: " + isLeapYearGregorianCalendar(2022)); - } -} \ No newline at end of file diff --git a/Konto/src/Konto.java b/Konto/src/Konto.java index b6fff52..53dcb7d 100644 --- a/Konto/src/Konto.java +++ b/Konto/src/Konto.java @@ -1,8 +1,33 @@ +/** + * Generic test class for implementing and testing + * a basic Konto + * _ _ _ _ + * __ ___ __(_) |_| |_ ___ _ __ | |__ _ _ + * \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | | + * \ V V /| | | | |_| || __/ | | | | |_) | |_| | + * \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, | + * |___/ + * ____ __ __ _ + * / ___|_ _____ _ __ \ \ / /__ __ _ ___| | + * \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ | + * ___) \ V / __/ | | | \ V / (_) | (_| | __/ | + * |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_| + * |___/ + * Licensed under the GPLv2 License, Version 2.0 (the "License"); + * Copyright (c) Sven Vogel + */ public class Konto { private double guthaben; - void abheben(double betrag) { + /** + * Get some money from the konto. + * If the betrag is less than the money contained by the konto, + * then the maximum possible amount is taken from the konto and a message is printed + * to System.out + * @param betrag the amount of money to get out of the konto + */ + public void abheben(double betrag) { var neuesGuthaben = guthaben - betrag; if (neuesGuthaben < 0) { System.out.println("Sie konnten nur " + guthaben + " abheben"); @@ -12,15 +37,23 @@ public class Konto { guthaben = neuesGuthaben; } - void einzahlen(double betrag) { + /** + * Put some money in the konto. + * @exception IllegalArgumentException When betrag is negative + * @param betrag the amount of money to add to the konto + */ + public void einzahlen(double betrag) { if (betrag < 0) { - System.err.println("no"); - return; + throw new IllegalArgumentException("Man kann keinen negativen Betrag einzahlen"); } this.guthaben += betrag; } - double getGuthaben() { + /** + * Get the amount of memory in the konto + * @return the amount of memory in the konto + */ + public double getGuthaben() { return guthaben; } @@ -29,7 +62,7 @@ public class Konto { konto.einzahlen(134); konto.einzahlen(0.345); - System.out.println("guthaben: " + konto.getGuthaben()); + System.out.println("Guthaben: " + konto.getGuthaben()); konto.abheben(1e6); } } diff --git a/Maximum/src/Main.java b/Maximum/src/Main.java index 0d332a2..ccbf87d 100644 --- a/Maximum/src/Main.java +++ b/Maximum/src/Main.java @@ -1,19 +1,58 @@ +/** + * Generic test class for implementing and testing + * custom minimum and maximum methods + * _ _ _ _ + * __ ___ __(_) |_| |_ ___ _ __ | |__ _ _ + * \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | | + * \ V V /| | | | |_| || __/ | | | | |_) | |_| | + * \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, | + * |___/ + * ____ __ __ _ + * / ___|_ _____ _ __ \ \ / /__ __ _ ___| | + * \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ | + * ___) \ V / __/ | | | \ V / (_) | (_| | __/ | + * |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_| + * |___/ + * Licensed under the GPLv2 License, Version 2.0 (the "License"); + * Copyright (c) Sven Vogel + */ public class Main { - static int max(int a, int b) { + /** + * compute the maximum of a and b + * @apiNote prints the result ot System.out + * @param a the first value to compute the maximum of + * @param b the second value to compute the maximum of + * @return the maximum of the two values + */ + private static int max(int a, int b) { int max = a > b ? a : b; System.out.println("max: " + max); return max; } - static int max(int a, int b, int c) { + /** + * Compute the maximum of a and b + * @param a the first value to compute the maximum of + * @param b the second value to compute the maximum of + * @param c the third value to compute the maximum of + * @return the maximum of the values + */ + private static int max(int a, int b, int c) { if (a < b) { return b > c ? c : a; } return a > c ? a : c; } - static double max(double a, double b, double c) { + /** + * Compute the minimum of a and b + * @param a the first value to compute the minimum of + * @param b the second value to compute the minimum of + * @param c the third value to compute the minimum of + * @return the minimum of the values + */ + private static double max(double a, double b, double c) { if (a < b) { return b > c ? c : a; } diff --git a/README.md b/README.md index d6c0184..87683d0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # Java-Programming +This repository contains most of the exercises from the Java course at the DHBW. +Most of the projects found in this repository must be compiled with at least Java version 11, due to features +being used such as the `var` keyword or pattern matching. +No projects utilize external dependencies not supplied by at least the Adopt OpenJDK. +The IDE used to write, test and execute the projects was Intellij-IDEA. +Therefore the projects have no direct compatibility with Eclipse. \ No newline at end of file diff --git a/Verzinsung/src/Main.java b/Verzinsung/src/Main.java index bca7a5d..0c42690 100644 --- a/Verzinsung/src/Main.java +++ b/Verzinsung/src/Main.java @@ -1,10 +1,39 @@ import javax.swing.*; +/** + * Generic test class for implementing and testing + * custom minimum and maximum methods + * _ _ _ _ + * __ ___ __(_) |_| |_ ___ _ __ | |__ _ _ + * \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | | + * \ V V /| | | | |_| || __/ | | | | |_) | |_| | + * \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, | + * |___/ + * ____ __ __ _ + * / ___|_ _____ _ __ \ \ / /__ __ _ ___| | + * \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ | + * ___) \ V / __/ | | | \ V / (_) | (_| | __/ | + * |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_| + * |___/ + * Licensed under the GPLv2 License, Version 2.0 (the "License"); + * Copyright (c) Sven Vogel + */ public class Main { - static double linearZins(double kp, double zs, int n) { + /** + * calculate the linear zins over a span of years + * @param kp kaptial to invest at the beginning + * @param zs zinssatz or the amount of increase in normalized percentage [0; 1] + * @param n number of years to calculate + * @return the total amount of money + */ + private static double linearZins(double kp, double zs, int n) { double k = kp; + if (n < 0) { + throw new IllegalArgumentException("years must not be negative"); + } + for (int i = 0; i < n; i++) { k += kp * zs; } @@ -12,9 +41,20 @@ public class Main { return k; } + /** + * calculate the exponetial zins over a span of years + * @param kp kaptial to invest at the beginning + * @param zs zinssatz or the amount of increase in normalized percentage [0; 1] + * @param n number of years to calculate + * @return the total amount of money + */ static double expZins(double kp, double zs, int n) { double k = kp; + if (n < 0) { + throw new IllegalArgumentException("years must not be negative"); + } + for (int i = 0; i < n; i++) { k += k * zs; } @@ -22,6 +62,13 @@ public class Main { return k; } + /** + * Opens system dialog requesting the user to enter a string. + * Ths string gets converted to a double and tested for its sign. + * If the input is invalid, i.e. not a unsigned rational number, the popup will appear again. + * @param message the message to be displayed + * @return the user input + */ static double enterUnsigendDouble(String message) { while (true) { try { diff --git a/Zaubern/src/Main.java b/Zaubern/src/Main.java index 73060d0..3c7f972 100644 --- a/Zaubern/src/Main.java +++ b/Zaubern/src/Main.java @@ -1,5 +1,26 @@ import java.util.Random; +/** + * Generic test class for implementing and testing + * custom minimum and maximum methods + * _ _ _ _ + * __ ___ __(_) |_| |_ ___ _ __ | |__ _ _ + * \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | | + * \ V V /| | | | |_| || __/ | | | | |_) | |_| | + * \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, | + * |___/ + * ____ __ __ _ + * / ___|_ _____ _ __ \ \ / /__ __ _ ___| | + * \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ | + * ___) \ V / __/ | | | \ V / (_) | (_| | __/ | + * |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_| + * |___/ + * Licensed under the GPLv2 License, Version 2.0 (the "License"); + * Copyright (c) Sven Vogel + * + * NOTE: following code mostly copied from the teacher, + * expect no comments or functionality + */ public class Main { enum Zauberspruch {