package de.sebhn.algorithm.excercise3;

import java.math.BigInteger;
import java.util.HashMap;

public class Fibonacci {
  static int betrag[] = {1, 3, 7, 31, 47};
  static int n = betrag.length; // Anzahl Muenzen

  static BigInteger w[][]; // Tabelle

  public static void main(String[] args) {
    for (int i = 0; i < 41; i++) {
      int g = F(i).intValue(); // g lesen
      int gPlusOne = g + 1;
      w = new BigInteger[gPlusOne][n]; // w dimensionieren
      for (int j = 0; j < gPlusOne; j++) {
        for (int l = 0; l < n; l++) {
          w[j][l] = BigInteger.ZERO;
        }
      }
      System.out.println(
          "Den Betrag " + g + " kann man auf " + w(g, n - 1) + " verschiedene Arten wecheln.");
    }
  }

  static HashMap<Integer, BigInteger> F = new HashMap<>(); // dynamic table

  public static BigInteger F(int n) { // method
    if (n <= 1) {
      return BigInteger.valueOf(n);
    } // base case
    BigInteger m = F.get(n); // lookup
    if (m != null)
      return m; // sucessful
    m = F(n - 1).add(F(n - 2)); // recursion
    F.put(n, m); // store
    return m; // finish
  }


  static BigInteger w(int g, int i) { // Methode
    return g < 0 ? BigInteger.ZERO
        : i == 0 ? (g % betrag[0] == 0 ? BigInteger.ONE : BigInteger.ZERO)
            : !w[g][i].equals(BigInteger.ZERO) ? w[g][i]
                : (w[g][i] = w(g, i - 1).add(w(g - betrag[i], i)));
  }

  public static int of(int n) {
    if (n == 0) {
      return 0;
    } else if (n == 1) {
      return 1;
    } else {
      return of(n - 1) + of(n - 2);
    }
  }
}

@@ -98,672 +98,451 @@
 %0D%0A%0D%0A
-public class Fibonacci %7B%0D%0A  static int betrag%5B%5D = %7B1, 3, 7, 31, 47%7D;%0D%0A  static int n = betrag.length; // Anzahl Muenzen%0D%0A%0D%0A  static BigInteger w%5B%5D%5B%5D
+/**%0D%0A * Is responsible for calculating fibonacci numbers%0D%0A */%0D%0Apublic class Fibonacci %7B%0D%0A%0D%0A  private static HashMap%3CInteger, BigInteger%3E B = new HashMap%3C%3E(40)
 ; // 
-Tabelle%0D%0A%0D%0A  public static void main(String%5B%5D args) %7B%0D%0A    for (int i = 0; i %3C 41; i++) %7B%0D%0A      int g = F(i).intValue(); // g lesen%0D%0A      int gPlusOne = g + 1;%0D%0A      w = new BigInteger%5BgPlusOne%5D%5Bn%5D; // w dimensionieren%0D%0A      for (int j = 0; j %3C gPlusOne; j++) %7B%0D%0A        for (int l = 0; l %3C n; l++) %7B%0D%0A          w%5Bj%5D%5Bl%5D = BigInteger.ZERO;%0D%0A        %7D
+table for storing already%0D%0A                                                                     // calculated fibonacci number%0D%0A
 %0D%0A  
-    %7D
+/**
 %0D%0A   
-   System.out.println(%0D%0A          %22Den Betrag %22 + g + %22 kann man auf %22 + w(g, n - 1) + %22 verschiedene Arten wecheln.%22);
+* calculates the 'n' fibonacci number%0D%0A   * %0D%0A   * @param n - the n fibonacci number%0D%0A   * @return fibonacci number
 %0D%0A   
- %7D
+*/
 %0D%0A  
-%7D%0D%0A%0D%0A 
+public
  static 
 Hash
@@ -541,138 +541,100 @@
 tic 
-HashMap%3CInteger, BigInteger%3E F = new HashMap%3C%3E(); // dynamic table%0D%0A%0D%0A  public static BigInteger F(int n) %7B // method%0D%0A   
+BigInteger of(int n) %7B%0D%0A    if (n == 0) %7B%0D%0A      return BigInteger.ZERO;%0D%0A    %7D else
  if (n 
-%3C
+=
 = 1)
@@ -665,41 +665,30 @@
 ger.
-valueOf(n);%0D%0A    %7D // base case%0D%0A
+ONE;%0D%0A    %7D else %7B%0D%0A  
     
@@ -698,21 +698,26 @@
 Integer 
-m = F
+number = B
 .get(n);
@@ -736,13 +736,20 @@
     
+  
 if (
-m
+number
  != 
@@ -757,604 +757,230 @@
 ull)
-%0D%0A      return m; // sucessful%0D%0A    m = F(n - 1).add(F(n - 2)); // recursion%0D%0A    F.put(n, m); // store%0D%0A    return m; // finish%0D%0A  %7D%0D%0A%0D%0A%0D%0A  static BigInteger w(int g, int i) %7B // Methode%0D%0A    return g %3C 0 ? BigInteger.ZERO%0D%0A        : i == 0 ? (g %25 betrag%5B0%5D == 0 ? BigInteger.ONE : BigInteger.ZERO)%0D%0A            : !w%5Bg%5D%5Bi%5D.equals(BigInteger.ZERO) ? w%5Bg%5D%5Bi%5D%0D%0A                : (w%5Bg%5D%5Bi%5D = w(g, i - 1).add(w(g - betrag%5Bi%5D, i)));%0D%0A  %7D%0D%0A%0D%0A  public static int of(int n) %7B
+ %7B%0D%0A        return number; // return looked up value%0D%0A      %7D else %7B%0D%0A        BigInteger newNumber = of(n - 1).add(of(n - 2)); // calculate
 %0D%0A    
-if (n == 0) %7B%0D%0A      return 0;%0D%0A    %7D else if (n == 1) %7B%0D%0A      return 1;%0D%0A    %7D else %7B%0D%0A      return of(n - 1) + of(n - 2);
+    B.put(n, newNumber); // put new value%0D%0A        return newNumber;%0D%0A      %7D
 %0D%0A  

remove unnecessary methods / implement/improve one method