Beabsichtigte Restschuld eingebaut
This commit is contained in:
		@@ -17,6 +17,7 @@ class Darlehenberechner {
 | 
			
		||||
      private BigDecimal zinssatzReal;
 | 
			
		||||
      private BigDecimal monatlicheRate;
 | 
			
		||||
      private Integer laufzeitMonate;
 | 
			
		||||
      private BigDecimal restschuld;
 | 
			
		||||
      private Integer tilgungsfreieZeit;
 | 
			
		||||
      private YearMonth anfangsmonat;
 | 
			
		||||
      private BigDecimal sondertilgungReal;
 | 
			
		||||
@@ -72,6 +73,17 @@ class Darlehenberechner {
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      public BigDecimal getRestschuld() {
 | 
			
		||||
         return restschuld;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      public Konfiguration setRestschuld(BigDecimal restschuld) {
 | 
			
		||||
         this.restschuld = restschuld;
 | 
			
		||||
         return this;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      public Integer getTilgungsfreieZeit() {
 | 
			
		||||
         return tilgungsfreieZeit;
 | 
			
		||||
      }
 | 
			
		||||
@@ -110,6 +122,7 @@ class Darlehenberechner {
 | 
			
		||||
   private static final BigDecimal EINHUNDERT = BigDecimal.valueOf(100);
 | 
			
		||||
 | 
			
		||||
   private final Integer laufzeitMonate;
 | 
			
		||||
   private final BigDecimal restschuld;
 | 
			
		||||
   private final BigDecimal zinssatz;
 | 
			
		||||
   private BigDecimal sondertilgung;
 | 
			
		||||
   private int summeMonate = 0;
 | 
			
		||||
@@ -164,6 +177,12 @@ class Darlehenberechner {
 | 
			
		||||
      if (in != null && !in.isBlank()) {
 | 
			
		||||
         String[] split = in.split(":");
 | 
			
		||||
         konfig.setLaufzeit(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
 | 
			
		||||
      } else {
 | 
			
		||||
         System.out.print("Restschuld(optional): ");
 | 
			
		||||
         in = dis.readLine();
 | 
			
		||||
         if (in != null && !in.isBlank()) {
 | 
			
		||||
            konfig.setRestschuld((BigDecimal) DECIMAL_FORMAT.parse(in));
 | 
			
		||||
         }
 | 
			
		||||
      }
 | 
			
		||||
      System.out.print("Anzahl tilgungsfreier Monate(optional): ");
 | 
			
		||||
      in = dis.readLine();
 | 
			
		||||
@@ -224,9 +243,13 @@ class Darlehenberechner {
 | 
			
		||||
 | 
			
		||||
   private Darlehenberechner(Konfiguration konfig) {
 | 
			
		||||
      laufzeitMonate = konfig.getLaufzeitMonate();
 | 
			
		||||
      restschuld = konfig.getRestschuld();
 | 
			
		||||
      zinssatz = konfig.getZinssatz();
 | 
			
		||||
      sondertilgung = konfig.getSondertilgung() != null ? konfig.getSondertilgung().multiply(konfig.getDarlehenswert()) : BigDecimal.ZERO;
 | 
			
		||||
      aktRestschuld = konfig.getDarlehenswert();
 | 
			
		||||
      if (restschuld != null) {
 | 
			
		||||
         aktRestschuld = aktRestschuld.subtract(restschuld);
 | 
			
		||||
      }
 | 
			
		||||
      aktMonatlicheRate = konfig.getMonatlicheRate();
 | 
			
		||||
      aktTilgungsfreieZeit = konfig.getTilgungsfreieZeit();
 | 
			
		||||
      aktMonat = konfig.getAnfangsmonat();
 | 
			
		||||
@@ -276,12 +299,17 @@ class Darlehenberechner {
 | 
			
		||||
      }
 | 
			
		||||
      boolean sondertilgungFaellingErstesJahr = summeMonate < 12 && aktMonat.getMonth() == Month.DECEMBER;
 | 
			
		||||
      if (sondertilgungFaellingErstesJahr || summeMonate > 1 && aktMonat.getMonth() == Month.JANUARY) {
 | 
			
		||||
         aktRestschuld = aktRestschuld.subtract(sondertilgung);
 | 
			
		||||
         System.out.println(aktMonat + ": " + DECIMAL_FORMAT.format(sondertilgung) + " = 0,00 + " + DECIMAL_FORMAT.format(sondertilgung) + " | " + DECIMAL_FORMAT.format(aktRestschuld));
 | 
			
		||||
         aktRestschuld = aktRestschuld.compareTo(sondertilgung) > 0 ? aktRestschuld.subtract(sondertilgung) : aktRestschuld;
 | 
			
		||||
         System.out.println(aktMonat + ": " + DECIMAL_FORMAT.format(sondertilgung) + " = 0,00 + " + DECIMAL_FORMAT.format(sondertilgung) + " | " + DECIMAL_FORMAT.format(getRestschuldFuerOutput()));
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
   private BigDecimal getRestschuldFuerOutput() {
 | 
			
		||||
      return restschuld != null ? aktRestschuld.add(restschuld) : aktRestschuld;
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
   private void berechneBeitragAufteilung() {
 | 
			
		||||
      aktZinsbetrag = aktRestschuld.multiply(zinssatz)
 | 
			
		||||
         .divide(ZWOELF, MathContext.DECIMAL128);
 | 
			
		||||
@@ -299,7 +327,7 @@ class Darlehenberechner {
 | 
			
		||||
 | 
			
		||||
   private void druckeAktuelleMonatswerte() {
 | 
			
		||||
      System.out.println(aktMonat + ": " + DECIMAL_FORMAT.format(aktMonatlicheRate) + " = " + DECIMAL_FORMAT.format(aktZinsbetrag)
 | 
			
		||||
            + " + " + DECIMAL_FORMAT.format(aktTilgungsbetrag) + " | " + DECIMAL_FORMAT.format(aktRestschuld));
 | 
			
		||||
            + " + " + DECIMAL_FORMAT.format(aktTilgungsbetrag) + " | " + DECIMAL_FORMAT.format(getRestschuldFuerOutput()));
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -331,7 +359,8 @@ class Darlehenberechner {
 | 
			
		||||
            jahressummeTilgungKreditjahr = BigDecimal.ZERO;
 | 
			
		||||
            jahressummeRatenKreditjahr = BigDecimal.ZERO;
 | 
			
		||||
            desc = "Kreditjahr " + (summeMonate + 11) / 12; // + 11 weil integerdivision und X Jahre plus 1 Monat soll X + 1 tes Kreditjahr ergeben
 | 
			
		||||
         } else {
 | 
			
		||||
         }
 | 
			
		||||
         if (aktMonat.getMonth() == Month.DECEMBER) {
 | 
			
		||||
            jahressummeZinsen = jahressummeZinsenKalenderjahr;
 | 
			
		||||
            jahressummeTilgung = jahressummeTilgungKalenderjahr;
 | 
			
		||||
            jahressummeRaten = jahressummeRatenKalenderjahr;
 | 
			
		||||
@@ -364,6 +393,6 @@ class Darlehenberechner {
 | 
			
		||||
      int laufzeitJahreFinal = summeMonate / 12;
 | 
			
		||||
      int teillaufzeitMonateFinal = summeMonate % 12;
 | 
			
		||||
      System.out.println("Laufzeit: " + laufzeitJahreFinal + " Jahre " + teillaufzeitMonateFinal + " Monate");
 | 
			
		||||
      System.out.println("Restschuld: " + DECIMAL_FORMAT.format(aktRestschuld));
 | 
			
		||||
      System.out.println("Restschuld: " + DECIMAL_FORMAT.format(getRestschuldFuerOutput()));
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user