Commit a3f25bfa authored by mohamad's avatar mohamad

Adding Normal Fibonacci

parent fa018a23
......@@ -30,9 +30,32 @@
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true"
},
"keyToStringList": {
"com.intellij.ide.scratch.ScratchImplUtil$2/New Scratch File": [
"PLAIN_TEXT"
]
}
}]]></component>
<component name="RunManager">
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="FibonacciSeries.implementation" />
</key>
</component>
<component name="RunManager" selected="Application.FibonacciSeries.runners.Main">
<configuration name="FibonacciSeries.runners.Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="FibonacciSeries.runners.Main" />
<module name="Lab1" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="FibonacciSeries.runners.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="threading.runners.Main" />
<module name="Lab1" />
......@@ -48,6 +71,7 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.FibonacciSeries.runners.Main" />
<item itemvalue="Application.Main" />
</list>
</recent_temporary>
......
FROM openjdk:17
COPY ./target/ /tmp
WORKDIR /tmp
ENTRYPOINT ["java","classes/runners/Main.class"]
\ No newline at end of file
RUN mkdir /app
COPY . /app
WORKDIR /app
CMD java src/main/java/threading/runners/Main.java
\ No newline at end of file
package FibonacciSeries.abstractions;
public interface IFibonacciCalculator {
long calculate(long number);
}
package FibonacciSeries.implementation;
import FibonacciSeries.abstractions.IFibonacciCalculator;
public class NormalFibonacciCalculator implements IFibonacciCalculator {
@Override
public long calculate(long number) {
long firstItem = 0;
long secondItem = 1;
if (number == 0) {
return firstItem;
}
if (number == 1) {
return secondItem;
}
long ans = 0;
for (int i = 2; i <= number; i++){
ans = secondItem + firstItem;
firstItem = secondItem;
secondItem = ans;
}
return ans;
}
}
package FibonacciSeries.implementation;
import FibonacciSeries.abstractions.IFibonacciCalculator;
public class ParallelFibonacciCalculator implements IFibonacciCalculator {
@Override
public long calculate(long number) {
return 0;
}
}
package FibonacciSeries.runners;
import FibonacciSeries.abstractions.IFibonacciCalculator;
import FibonacciSeries.implementation.NormalFibonacciCalculator;
public class Main {
public static void main(String[] args) {
IFibonacciCalculator calculator = new NormalFibonacciCalculator();
for (int i = 0; i < 10; i++) {
System.out.println("F("+i+") = "+calculator.calculate(i));
}
}
}
......@@ -8,6 +8,7 @@ import java.util.Collection;
public class ParallelPrimeNumbersExtractor implements IPrimeNumbersExtractor {
private final int _numberOfThreads;
// https://www.primesfordays.com/api/primes/nth/555/ for testing purposes
public ParallelPrimeNumbersExtractor(int numberOfThreads) {
_numberOfThreads = numberOfThreads;
}
......
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