- cli-funktionalität hinzugefügt
- weitere Details ausgedruckt
This commit is contained in:
		@@ -1,8 +1,11 @@
 | 
			
		||||
import java.text.DecimalFormat;
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.math.MathContext;
 | 
			
		||||
import java.text.DecimalFormat;
 | 
			
		||||
import java.text.DecimalFormatSymbols;
 | 
			
		||||
import java.text.ParseException;
 | 
			
		||||
import java.time.Month;
 | 
			
		||||
import java.time.YearMonth;
 | 
			
		||||
import java.util.Locale;
 | 
			
		||||
 | 
			
		||||
class Darlehenberechner {
 | 
			
		||||
 | 
			
		||||
@@ -82,26 +85,63 @@ class Darlehenberechner {
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,##0.00");
 | 
			
		||||
   private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,##0.00", new DecimalFormatSymbols(Locale.GERMAN));
 | 
			
		||||
   private static final BigDecimal ZWOELF = BigDecimal.valueOf(12);
 | 
			
		||||
 | 
			
		||||
      public static void main(String[] args) {
 | 
			
		||||
         var konfig = new Konfiguration()
 | 
			
		||||
      public static void main(String[] args) throws ParseException {
 | 
			
		||||
         /*berechneWerte(new Konfiguration()
 | 
			
		||||
            .setDarlehenswert(BigDecimal.valueOf(168_000))
 | 
			
		||||
            .setZinssatzProzent(BigDecimal.valueOf(3.73))
 | 
			
		||||
            .setMonatlicheRate(BigDecimal.valueOf(1_500))
 | 
			
		||||
            .setTilgungsfreieZeit(0)
 | 
			
		||||
            .setAnfangsmonat(YearMonth.of(2024, Month.SEPTEMBER));
 | 
			
		||||
         berechneWerte(konfig);
 | 
			
		||||
            .setAnfangsmonat(YearMonth.of(2024, Month.SEPTEMBER)));
 | 
			
		||||
         return;*/
 | 
			
		||||
 | 
			
		||||
         /*var konfig = new Konfiguration()
 | 
			
		||||
         /*berechneWerte(new Konfiguration()
 | 
			
		||||
            .setDarlehenswert(BigDecimal.valueOf(168_000))
 | 
			
		||||
            .setZinssatzProzent(BigDecimal.valueOf(3.73))
 | 
			
		||||
            .setMonatlicheRate(BigDecimal.valueOf(1_500))
 | 
			
		||||
            .setTilgungsfreieZeit(0)
 | 
			
		||||
            .setLaufzeitJahre(11)
 | 
			
		||||
            .setAnfangsmonat(YearMonth.of(2024, Month.SEPTEMBER));
 | 
			
		||||
         berechneWerte(konfig);*/
 | 
			
		||||
            .setAnfangsmonat(YearMonth.of(2024, Month.SEPTEMBER)));
 | 
			
		||||
         return;*/
 | 
			
		||||
 | 
			
		||||
         var konfig = new Konfiguration();
 | 
			
		||||
         int count = 0;
 | 
			
		||||
         DECIMAL_FORMAT.setParseBigDecimal(true);
 | 
			
		||||
         while (count < args.length) {
 | 
			
		||||
            String arg = args[count];
 | 
			
		||||
            if (arg.equals("-hilfe")) {
 | 
			
		||||
               System.out.println("-darlehenswert 1000,00 -zinssatz 3,73 -monatlicheRate 30,00 -anfangsmonat 2024-09"
 | 
			
		||||
                  + "[-laufzeitJahre 11] [-tilgungsfreieZeit 5]");
 | 
			
		||||
            }
 | 
			
		||||
            if (arg.equals("-darlehenswert")) {
 | 
			
		||||
               count++;
 | 
			
		||||
               konfig.setDarlehenswert((BigDecimal) DECIMAL_FORMAT.parse(args[count]));
 | 
			
		||||
            }
 | 
			
		||||
            if (arg.equals("-zinssatz")) {
 | 
			
		||||
               count++;
 | 
			
		||||
               konfig.setZinssatzProzent((BigDecimal) DECIMAL_FORMAT.parse(args[count]));
 | 
			
		||||
            }
 | 
			
		||||
            if (arg.equals("-monatlicheRate")) {
 | 
			
		||||
               count++;
 | 
			
		||||
               konfig.setMonatlicheRate((BigDecimal) DECIMAL_FORMAT.parse(args[count]));
 | 
			
		||||
            }
 | 
			
		||||
            if (arg.equals("-tilgungsfreieZeit")) {
 | 
			
		||||
               count++;
 | 
			
		||||
               konfig.setTilgungsfreieZeit(Integer.parseInt(args[count]));
 | 
			
		||||
            }
 | 
			
		||||
            if (arg.equals("-laufzeitJahre")) {
 | 
			
		||||
               count++;
 | 
			
		||||
               konfig.setLaufzeitJahre(Integer.parseInt(args[count]));
 | 
			
		||||
            }
 | 
			
		||||
            if (arg.equals("-anfangsmonat")) {
 | 
			
		||||
               count++;
 | 
			
		||||
               konfig.setAnfangsmonat(YearMonth.parse(args[count]));
 | 
			
		||||
            }
 | 
			
		||||
            count++;
 | 
			
		||||
         }
 | 
			
		||||
         berechneWerte(konfig);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -114,7 +154,11 @@ class Darlehenberechner {
 | 
			
		||||
      YearMonth aktuellerMonat = konfig.getAnfangsmonat();
 | 
			
		||||
      BigDecimal summeZinsen = BigDecimal.ZERO;
 | 
			
		||||
      BigDecimal summeTilgung = BigDecimal.ZERO;
 | 
			
		||||
      BigDecimal jahressummeRatenKalenderjahr = BigDecimal.ZERO;
 | 
			
		||||
      BigDecimal jahressummeRatenKreditjahr = BigDecimal.ZERO;
 | 
			
		||||
      BigDecimal summeRaten = BigDecimal.ZERO;
 | 
			
		||||
      int laufzeitMonate = 0;
 | 
			
		||||
      System.out.println("Monat:   Rate     = Zinsen + Tilgung| Restschuld");
 | 
			
		||||
      while ((laufzeitJahre == null || laufzeitMonate < (laufzeitJahre * 12)) && restschuld.signum() > 0) {
 | 
			
		||||
         // berechne Beträge/ aktualisiere Restschuld
 | 
			
		||||
         BigDecimal zinsbetrag = restschuld.multiply(zinssatzReal).divide(ZWOELF, MathContext.DECIMAL128);
 | 
			
		||||
@@ -128,8 +172,24 @@ class Darlehenberechner {
 | 
			
		||||
         // berechne Summen für Zusammenfassung
 | 
			
		||||
         summeZinsen = summeZinsen.add(zinsbetrag);
 | 
			
		||||
         summeTilgung = summeTilgung.add(tilgungsbetrag);
 | 
			
		||||
         if ((laufzeitMonate > 0 && laufzeitMonate % 11 == 0) || aktuellerMonat.getMonthValue() == 12) {
 | 
			
		||||
            System.out.println("                    " + DECIMAL_FORMAT.format(summeZinsen) + " + " + DECIMAL_FORMAT.format(summeTilgung));
 | 
			
		||||
         jahressummeRatenKalenderjahr = jahressummeRatenKalenderjahr.add(monatlicheRate);
 | 
			
		||||
         jahressummeRatenKreditjahr = jahressummeRatenKreditjahr.add(monatlicheRate);
 | 
			
		||||
         summeRaten = summeRaten.add(monatlicheRate);
 | 
			
		||||
         boolean kreditjahrVergangen = laufzeitMonate > 0 && laufzeitMonate % 11 == 0;
 | 
			
		||||
         if (kreditjahrVergangen || aktuellerMonat.getMonthValue() == 12) {
 | 
			
		||||
            BigDecimal jahressummeRaten;
 | 
			
		||||
            String desc;
 | 
			
		||||
            if (kreditjahrVergangen) {
 | 
			
		||||
               jahressummeRaten = jahressummeRatenKreditjahr;
 | 
			
		||||
               jahressummeRatenKreditjahr = BigDecimal.ZERO;
 | 
			
		||||
               desc = "Kreditjahr";
 | 
			
		||||
            } else {
 | 
			
		||||
               jahressummeRaten = jahressummeRatenKalenderjahr;
 | 
			
		||||
               jahressummeRatenKalenderjahr = BigDecimal.ZERO;
 | 
			
		||||
               desc = "Kalenderjahr";
 | 
			
		||||
            }
 | 
			
		||||
            System.out.println("Summe " + desc + ":\n" + DECIMAL_FORMAT.format(jahressummeRaten) + " = "
 | 
			
		||||
               + DECIMAL_FORMAT.format(summeZinsen) + " + " + DECIMAL_FORMAT.format(summeTilgung));
 | 
			
		||||
         }
 | 
			
		||||
         // aktualisiere Werte für den nächsten Lauf
 | 
			
		||||
         aktuellerMonat = aktuellerMonat.plusMonths(1);
 | 
			
		||||
@@ -139,7 +199,8 @@ class Darlehenberechner {
 | 
			
		||||
         }
 | 
			
		||||
      }
 | 
			
		||||
      // letzte Zusammenfassung
 | 
			
		||||
      System.out.println("                    " + DECIMAL_FORMAT.format(summeZinsen) + " + " + DECIMAL_FORMAT.format(summeTilgung));
 | 
			
		||||
      System.out.println("Summe:\n" + DECIMAL_FORMAT.format(summeRaten) + " = "
 | 
			
		||||
         + DECIMAL_FORMAT.format(summeZinsen) + " + " + DECIMAL_FORMAT.format(summeTilgung));
 | 
			
		||||
      // Ausgabe Laufzeit + Restschuld
 | 
			
		||||
      laufzeitJahre = laufzeitJahre == null ? laufzeitMonate / 12 : laufzeitJahre;
 | 
			
		||||
      int laufzeitMonateTeil = laufzeitMonate - (laufzeitJahre * 12);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user