mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-02-16 11:31:01 +01:00
implement Modulo
This commit is contained in:
parent
9f4fc90a37
commit
08dccc68ba
@ -24,6 +24,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private static final int MINUS = 3;
|
private static final int MINUS = 3;
|
||||||
private static final int MULTIPLY = 4;
|
private static final int MULTIPLY = 4;
|
||||||
private static final int DIVIDE = 5;
|
private static final int DIVIDE = 5;
|
||||||
|
private static final int MODULO = 6;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -67,6 +68,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
updateResult(resultValue);
|
updateResult(resultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void moduloNumbers() {
|
||||||
|
double resultValue = 0;
|
||||||
|
if (secondValue != 0)
|
||||||
|
resultValue = baseValue % secondValue;
|
||||||
|
|
||||||
|
updateResult(resultValue);
|
||||||
|
}
|
||||||
|
|
||||||
private void handleOperation(int operation) {
|
private void handleOperation(int operation) {
|
||||||
if (lastKey == operation)
|
if (lastKey == operation)
|
||||||
return;
|
return;
|
||||||
@ -101,6 +110,11 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
handleOperation(DIVIDE);
|
handleOperation(DIVIDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.btn_modulo)
|
||||||
|
public void moduloClicked() {
|
||||||
|
handleOperation(MODULO);
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick(R.id.btn_equals)
|
@OnClick(R.id.btn_equals)
|
||||||
public void equalsClicked() {
|
public void equalsClicked() {
|
||||||
if (lastKey == EQUALS)
|
if (lastKey == EQUALS)
|
||||||
@ -147,6 +161,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
case DIVIDE:
|
case DIVIDE:
|
||||||
divideNumbers();
|
divideNumbers();
|
||||||
break;
|
break;
|
||||||
|
case MODULO:
|
||||||
|
moduloNumbers();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user