Commit 45183747 authored by mohamad's avatar mohamad

Adding Math Fibonacci

parent a3f25bfa
package FibonacciSeries.abstractions;
public interface IFibonacciCalculator {
long calculate(long number);
double calculate(long number);
}
package FibonacciSeries.implementation;
import FibonacciSeries.abstractions.IFibonacciCalculator;
public class MathFibonacciCalculator implements IFibonacciCalculator {
@Override
public double calculate(long number) {
double item1 = (1 + Math.sqrt(5))/2;
double item2 = (1 - Math.sqrt(5))/2;
item1 = Math.pow(item1,number);
item2 = Math.pow(item2,number);
return Math.round((item1 + item2)/Math.sqrt(5));
}
}
......@@ -4,7 +4,7 @@ import FibonacciSeries.abstractions.IFibonacciCalculator;
public class NormalFibonacciCalculator implements IFibonacciCalculator {
@Override
public long calculate(long number) {
public double calculate(long number) {
long firstItem = 0;
long secondItem = 1;
......
......@@ -4,7 +4,7 @@ import FibonacciSeries.abstractions.IFibonacciCalculator;
public class ParallelFibonacciCalculator implements IFibonacciCalculator {
@Override
public long calculate(long number) {
public double calculate(long number) {
return 0;
}
}
package FibonacciSeries.runners;
import FibonacciSeries.abstractions.IFibonacciCalculator;
import FibonacciSeries.implementation.MathFibonacciCalculator;
import FibonacciSeries.implementation.NormalFibonacciCalculator;
public class Main {
public static void main(String[] args) {
IFibonacciCalculator calculator = new NormalFibonacciCalculator();
IFibonacciCalculator calculator = new MathFibonacciCalculator();
for (int i = 0; i < 10; i++) {
System.out.println("F("+i+") = "+calculator.calculate(i));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment