diff options
author | braxtonhall | 2022-10-24 02:13:46 +0000 |
---|---|---|
committer | braxtonhall | 2022-10-24 02:13:46 +0000 |
commit | 46a659c983911b87b38b20cd4b28ab9176e4fdb3 (patch) | |
tree | a0feef04229b8a9cf19d4a14eb29f773c4f394ef /entries/nritschel/fib-java/src/Main.java | |
parent | f4e141bb52b93096642a81a35b28c59dcc8dcdb5 (diff) |
Add fib-java
Diffstat (limited to 'entries/nritschel/fib-java/src/Main.java')
-rw-r--r-- | entries/nritschel/fib-java/src/Main.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/entries/nritschel/fib-java/src/Main.java b/entries/nritschel/fib-java/src/Main.java new file mode 100644 index 0000000..8ae46f1 --- /dev/null +++ b/entries/nritschel/fib-java/src/Main.java @@ -0,0 +1,21 @@ +public class Main { + public static void main(String[] args) { + if (args.length < 1) { + System.out.println(""" + Please provide: + 1. fibonacci number to compute, and + 2. (optional) the calculation method (naive or cached)."""); + } + else { + FibonacciNumberFactory factory; + if (args.length >= 2 && args[1].equals("naive")) { + factory = new NaiveFibonacciNumberFactory(); + } + else { + factory = new CachedFibonacciNumberFactory(); + } + FibonacciCalculator calculator = new FibonacciCalculatorImpl(factory); + System.out.println(factory.getFibonacciNumber(Integer.parseInt(args[0])).calculate(calculator)); + } + } +} |