From b1d4deb0e3ccbf31e097e670ec9df087455f3cc0 Mon Sep 17 00:00:00 2001 From: Sebastian Brosch Date: Mon, 13 May 2024 16:04:23 +0200 Subject: [PATCH] Vorlesung 4 / Aufgabe 4 --- S01-VL04-Aufgabe 4/Aufgabe.java | 32 ---------------------------- VL04/Aufgabe04/Aufgabe04.java | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 32 deletions(-) delete mode 100644 S01-VL04-Aufgabe 4/Aufgabe.java create mode 100644 VL04/Aufgabe04/Aufgabe04.java diff --git a/S01-VL04-Aufgabe 4/Aufgabe.java b/S01-VL04-Aufgabe 4/Aufgabe.java deleted file mode 100644 index a547a2f..0000000 --- a/S01-VL04-Aufgabe 4/Aufgabe.java +++ /dev/null @@ -1,32 +0,0 @@ -class Aufgabe { - public static void main(String[] args) { - final int laufzeit = 10; - final double startwert = 100.0; - - // Die verschiedenen Zinssätze definieren. - double zinssatz[] = {3.5, 4.5, 5.5}; - - // Es kann eine Matrix erstellt werden in welcher die Informationen für die Entwicklung gespeichert werden. - // Die Zeilen sind die Informationen der Jahre. Die Spalten sind die Entwicklung je nach Zinssatz. - double entwicklung[][] = new double[laufzeit][3]; - - // Für jedes Jahr muss die Entwicklung angepasst werden. - for(int i = 0; i < laufzeit; i++) { - for(int z = 0; z < zinssatz.length; z++) { - double wert = (i == 0) ? startwert : entwicklung[i-1][z]; - entwicklung[i][z] = wert + (wert * (zinssatz[z] / 100.0)); - } - } - - // Die Parameter ausgeben damit die Grundlage der Entwicklung sichtbar ist. - System.out.printf("Laufzeit: %d Jahre - Startwert: %.2f EUR\n\n", laufzeit, startwert); - - // Die Kopfleiste für die Tabelle ausgeben. - System.out.printf("Jahr\t%11.2f%%\t%11.2f%%\t%11.2f%%\n", zinssatz[0], zinssatz[1], zinssatz[2]); - - // Die Informationen der Entwicklung ausgeben. - for(int i = 0; i < entwicklung.length; i++) { - System.out.printf("%d\t%8.2f EUR\t%8.2f EUR\t%8.2f EUR\n", (2023 + 1) + i, entwicklung[i][0], entwicklung[i][1], entwicklung[i][2]); - } - } -} diff --git a/VL04/Aufgabe04/Aufgabe04.java b/VL04/Aufgabe04/Aufgabe04.java new file mode 100644 index 0000000..a3fc1f8 --- /dev/null +++ b/VL04/Aufgabe04/Aufgabe04.java @@ -0,0 +1,37 @@ +package VL04.Aufgabe04; + +/** + * Vorlesung 4 / Aufgabe 4 + * + * @author Sebastian Brosch + */ +public class Aufgabe04 { + public static void main(String[] args) { + final int laufzeit = 4; + final double startwert = 100.0; + final double[] zinssaetze = { 2.0, 2.5, 3.0 }; + double entwicklung[][] = new double[laufzeit][zinssaetze.length]; + + for (int i = 0; i < laufzeit; i++) { + for (int z = 0; z < zinssaetze.length; z++) { + double wert = (i == 0) ? startwert : entwicklung[i - 1][z]; + entwicklung[i][z] = wert + (wert * (zinssaetze[z] / 100.0)); + } + } + + System.out.printf("Laufzeit: %d Jahre - Startwert: %.2f EUR\n\n", laufzeit, startwert); + System.out.printf("Jahr"); + + for (int z = 0; z < zinssaetze.length; z++) { + System.out.printf("\t%11.2f%%", zinssaetze[z]); + } + + for (int i = 0; i < entwicklung.length; i++) { + System.out.printf("\n%d", (2023 + 1) + i); + + for (int z = 0; z < zinssaetze.length; z++) { + System.out.printf("\t%8.2f EUR", entwicklung[i][z]); + } + } + } +}