Commit a7f786a9 authored by mohamad's avatar mohamad

Adding range calculator

parent f38a91c0
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES"> <option name="RECENT_TEMPLATES">
<list> <list>
<option value="Interface" />
<option value="Class" /> <option value="Class" />
<option value="Interface" />
</list> </list>
</option> </option>
</component> </component>
...@@ -49,11 +49,11 @@ ...@@ -49,11 +49,11 @@
</component> </component>
<component name="RunManager" selected="Application.fibonacciSeries.runners.Main"> <component name="RunManager" selected="Application.fibonacciSeries.runners.Main">
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="threading.runners.Main" /> <option name="MAIN_CLASS_NAME" value="primeNumbers.runners.Main" />
<module name="Lab1" /> <module name="Lab1" />
<extension name="coverage"> <extension name="coverage">
<pattern> <pattern>
<option name="PATTERN" value="threading.runners.*" /> <option name="PATTERN" value="primeNumbers.runners.*" />
<option name="ENABLED" value="true" /> <option name="ENABLED" value="true" />
</pattern> </pattern>
</extension> </extension>
......
package fibonacciSeries.abstractions; package fibonacciSeries.abstractions;
import fibonacciSeries.utilities.FibonacciStructure;
import java.util.List; import java.util.List;
public interface IFibonacciRangeCalculator { public interface IFibonacciRangeCalculator {
List<Long> calculate(long start, long end); List<FibonacciStructure> calculate(long start, long end);
} }
package fibonacciSeries.implementation.range; package fibonacciSeries.implementation.range;
import fibonacciSeries.abstractions.IFibonacciRangeCalculator; import fibonacciSeries.abstractions.IFibonacciRangeCalculator;
import fibonacciSeries.utilities.FibonacciStructure;
import fibonacciSeries.utilities.FibonacciStructureService;
import fibonacciSeries.utilities.IFibonacciStructureService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FibonacciRangeCalculatorUsingStructure implements IFibonacciRangeCalculator { public class FibonacciRangeCalculatorUsingStructure implements IFibonacciRangeCalculator {
private IFibonacciStructure _firstItem; private final FibonacciStructure _fZeroOfTheRange;
private IFibonacciStructure _secondItem; private final FibonacciStructure _fOneOfTheRange;
public FibonacciRangeCalculatorUsingStructure(IFibonacciStructure _firstItem, IFibonacciStructure _secondItem) { public FibonacciRangeCalculatorUsingStructure(FibonacciStructure _fZeroOfTheRange, FibonacciStructure _fOneOfTheRange) {
this._firstItem = _firstItem; this._fZeroOfTheRange = _fZeroOfTheRange;
this._secondItem = _secondItem; this._fOneOfTheRange = _fOneOfTheRange;
} }
@Override @Override
public List<Long> calculate(long start, long end) { public List<FibonacciStructure> calculate(long start, long end) {
ArrayList<Long> result = new ArrayList<>(); IFibonacciStructureService service = new FibonacciStructureService();
List<FibonacciStructure> result = new ArrayList<>();
FibonacciStructure first = _fZeroOfTheRange;
FibonacciStructure second = _fOneOfTheRange;
for(long i = start; i < end; i++) {
FibonacciStructure pushed = service.add(first, second);
result.add(pushed);
first = second;
second = pushed;
}
return result; return result;
} }
} }
...@@ -3,15 +3,21 @@ package fibonacciSeries.utilities; ...@@ -3,15 +3,21 @@ package fibonacciSeries.utilities;
public class FibonacciStructure { public class FibonacciStructure {
private Long _xParameter; private Long _xParameter;
private Long _yParameter; private Long _yParameter;
private Integer Index;
public FibonacciStructure(Long _xParameter, Long _yParameter, Integer index) { public FibonacciStructure(Long _xParameter, Long _yParameter) {
this._xParameter = _xParameter; this._xParameter = _xParameter;
this._yParameter = _yParameter; this._yParameter = _yParameter;
Index = index;
} }
public Long getFibonacciValue(Integer trigger0, Integer trigger1) { public Long getXParameter() {
return _xParameter * trigger0 + _yParameter * trigger1; return _xParameter;
}
public Long getYParameter() {
return _yParameter;
}
public Long getFibonacciValue(Integer xValue, Integer yValue) {
return _xParameter * xValue + _yParameter * yValue;
} }
} }
package fibonacciSeries.utilities;
public class FibonacciStructureService implements IFibonacciStructureService {
@Override
public FibonacciStructure add(FibonacciStructure first, FibonacciStructure second) {
return new FibonacciStructure(first.getXParameter()+second.getXParameter(),
second.getYParameter()+first.getYParameter());
}
}
package fibonacciSeries.utilities;
public interface IFibonacciStructureService {
FibonacciStructure add(FibonacciStructure first,FibonacciStructure second);
}
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