examplecalculator.objectmodel.ElementFactorial Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of GradleProject.Calculate Show documentation
Show all versions of GradleProject.Calculate Show documentation
Project to ease pain of test automation
The newest version!
package examplecalculator.objectmodel;
import static examplecalculator.objectmodel.Element.TypeElement.FACTORIAL;
public final class ElementFactorial implements Element {
private String element;
private Double value;
public ElementFactorial(String element) {
this.element = element;
}
public ElementFactorial(String element, Double value) {
this.element = element;
this.value = getFactorial(value);
}
@Override
public Double getValue() {
return value;
}
@Override
public String getElement() {
return element;
}
@Override
public void setValue(Double value) {
this.value = value;
}
@Override
public void setElement(String element) {
this.element = element;
}
@Override
public TypeElement getTypeElement() {
return FACTORIAL;
}
/**
* Находит факториал числа
* @param number - число
* @return - возвращает факториал числа типом Double
*/
private static Double getFactorial(final Double number) {
if (number < 0)
throw new ArithmeticException("Отрицательный аргумент факториала");
if (number % 1 !=0)
throw new ArithmeticException("Аргумент факториала не является целым числом");
if (number == 0 || number == 1)
return 1.0;
else
return number * getFactorial(number-1);
}
}