From 88565fc74822b0ff9fa8150b665878be96cbba33 Mon Sep 17 00:00:00 2001 From: Sissy Dalampira Date: Thu, 4 Oct 2018 21:23:40 +0300 Subject: [PATCH] Adding FactorialOperation class --- .../operation/FactorialOperation.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calculator/operation/FactorialOperation.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/operation/FactorialOperation.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/operation/FactorialOperation.kt new file mode 100644 index 00000000..c3dd3131 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/operation/FactorialOperation.kt @@ -0,0 +1,26 @@ +package com.simplemobiletools.calculator.operation + +import com.simplemobiletools.calculator.operation.base.BinaryOperation +import com.simplemobiletools.calculator.operation.base.Operation +import com.simplemobiletools.calculator.operation.base.UnaryOperation + +class ParOperation(value: Double) : UnaryOperation(value), Operation { + + override fun getResult(): Double { + var result = 1.0 + if (value==0.0 || value==1.0){ + return result + } + else { + var base: Int + base = value.toInt() + for (i in 1..base){ + //Find Factorial of a number using for loop + result *= i + + } + } + return result + + } +} \ No newline at end of file