Commit a7f786a9 authored by mohamad's avatar mohamad

Adding range calculator

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