updated license information
This commit is contained in:
parent
09266228ab
commit
32ba8f6958
|
@ -3,7 +3,7 @@
|
|||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/GgtUndKgv/GgtUndKgv.iml" filepath="$PROJECT_DIR$/GgtUndKgv/GgtUndKgv.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/GreogorianischerKalender/GreogorianischerKalender.iml" filepath="$PROJECT_DIR$/GreogorianischerKalender/GreogorianischerKalender.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$/Konto/Konto.iml" filepath="$PROJECT_DIR$/Konto/Konto.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Maximum/Maximum.iml" filepath="$PROJECT_DIR$/Maximum/Maximum.iml" />
|
||||
|
|
|
@ -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
|
||||
* <p>
|
||||
* Licensed under the GPLv2 License, Version 2.0 (the "License");
|
||||
* Copyright (c) Sven Vogel
|
||||
* <p>
|
||||
* NOTE: following code mostly copied from the teacher,
|
||||
* expect no comments or functionality
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue