implement Modulo

This commit is contained in:
tibbi 2015-12-25 14:39:26 +01:00
parent 9f4fc90a37
commit 08dccc68ba
1 changed files with 17 additions and 0 deletions

View File

@ -24,6 +24,7 @@ public class MainActivity extends AppCompatActivity {
private static final int MINUS = 3;
private static final int MULTIPLY = 4;
private static final int DIVIDE = 5;
private static final int MODULO = 6;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -67,6 +68,14 @@ public class MainActivity extends AppCompatActivity {
updateResult(resultValue);
}
private void moduloNumbers() {
double resultValue = 0;
if (secondValue != 0)
resultValue = baseValue % secondValue;
updateResult(resultValue);
}
private void handleOperation(int operation) {
if (lastKey == operation)
return;
@ -101,6 +110,11 @@ public class MainActivity extends AppCompatActivity {
handleOperation(DIVIDE);
}
@OnClick(R.id.btn_modulo)
public void moduloClicked() {
handleOperation(MODULO);
}
@OnClick(R.id.btn_equals)
public void equalsClicked() {
if (lastKey == EQUALS)
@ -147,6 +161,9 @@ public class MainActivity extends AppCompatActivity {
case DIVIDE:
divideNumbers();
break;
case MODULO:
moduloNumbers();
break;
default:
break;
}