implement Root

This commit is contained in:
tibbi 2015-12-26 14:24:52 +01:00
parent 0e216ad692
commit aa6ebd00b3
1 changed files with 14 additions and 3 deletions

View File

@ -82,9 +82,7 @@ public class MainActivity extends AppCompatActivity {
return; return;
if (lastKey == DIGIT) { if (lastKey == DIGIT) {
secondValue = getDisplayedNumberAsDouble(); getResult();
calculateResult();
baseValue = getDisplayedNumberAsDouble();
} }
resetValue = true; resetValue = true;
lastKey = operation; lastKey = operation;
@ -116,6 +114,13 @@ public class MainActivity extends AppCompatActivity {
handleOperation(MODULO); handleOperation(MODULO);
} }
@OnClick(R.id.btn_root)
public void rootClicked() {
getResult();
lastOperation = EQUALS;
updateResult(Math.sqrt(baseValue));
}
@OnClick(R.id.btn_equals) @OnClick(R.id.btn_equals)
public void equalsClicked() { public void equalsClicked() {
if (lastKey == EQUALS) if (lastKey == EQUALS)
@ -153,6 +158,12 @@ public class MainActivity extends AppCompatActivity {
baseValue = value; baseValue = value;
} }
private void getResult() {
secondValue = getDisplayedNumberAsDouble();
calculateResult();
baseValue = getDisplayedNumberAsDouble();
}
private void calculateResult() { private void calculateResult() {
switch (lastOperation) { switch (lastOperation) {
case PLUS: case PLUS: