From aa6ebd00b3c50135f5639515d99cbb46cc185869 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 26 Dec 2015 14:24:52 +0100 Subject: [PATCH] implement Root --- .../com/simple_calculator/MainActivity.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/calculator/simplemobiletools/com/simple_calculator/MainActivity.java b/app/src/main/java/calculator/simplemobiletools/com/simple_calculator/MainActivity.java index bbfff066..fbce4d53 100644 --- a/app/src/main/java/calculator/simplemobiletools/com/simple_calculator/MainActivity.java +++ b/app/src/main/java/calculator/simplemobiletools/com/simple_calculator/MainActivity.java @@ -82,9 +82,7 @@ public class MainActivity extends AppCompatActivity { return; if (lastKey == DIGIT) { - secondValue = getDisplayedNumberAsDouble(); - calculateResult(); - baseValue = getDisplayedNumberAsDouble(); + getResult(); } resetValue = true; lastKey = operation; @@ -116,6 +114,13 @@ public class MainActivity extends AppCompatActivity { handleOperation(MODULO); } + @OnClick(R.id.btn_root) + public void rootClicked() { + getResult(); + lastOperation = EQUALS; + updateResult(Math.sqrt(baseValue)); + } + @OnClick(R.id.btn_equals) public void equalsClicked() { if (lastKey == EQUALS) @@ -153,6 +158,12 @@ public class MainActivity extends AppCompatActivity { baseValue = value; } + private void getResult() { + secondValue = getDisplayedNumberAsDouble(); + calculateResult(); + baseValue = getDisplayedNumberAsDouble(); + } + private void calculateResult() { switch (lastOperation) { case PLUS: