implement multiplication
This commit is contained in:
parent
82521af7b0
commit
3be2aee4d3
|
@ -22,6 +22,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private static final int EQUALS = 1;
|
private static final int EQUALS = 1;
|
||||||
private static final int PLUS = 2;
|
private static final int PLUS = 2;
|
||||||
private static final int MINUS = 3;
|
private static final int MINUS = 3;
|
||||||
|
private static final int MULTIPLY = 4;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -69,6 +70,12 @@ public class MainActivity extends AppCompatActivity {
|
||||||
baseValue = resultValue;
|
baseValue = resultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void multiplyNumbers() {
|
||||||
|
final double resultValue = baseValue * secondValue;
|
||||||
|
result.setText(Formatter.doubleToString(resultValue));
|
||||||
|
baseValue = resultValue;
|
||||||
|
}
|
||||||
|
|
||||||
private void handleOperation(int operation) {
|
private void handleOperation(int operation) {
|
||||||
if (lastKey == operation)
|
if (lastKey == operation)
|
||||||
return;
|
return;
|
||||||
|
@ -93,6 +100,11 @@ public class MainActivity extends AppCompatActivity {
|
||||||
handleOperation(MINUS);
|
handleOperation(MINUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.btn_multiply)
|
||||||
|
public void multiplyClicked() {
|
||||||
|
handleOperation(MULTIPLY);
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick(R.id.btn_equals)
|
@OnClick(R.id.btn_equals)
|
||||||
public void equalsClicked() {
|
public void equalsClicked() {
|
||||||
if (lastKey == EQUALS) {
|
if (lastKey == EQUALS) {
|
||||||
|
@ -113,6 +125,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
addNumbers();
|
addNumbers();
|
||||||
else if (lastOperation == MINUS)
|
else if (lastOperation == MINUS)
|
||||||
subtractNumbers();
|
subtractNumbers();
|
||||||
|
else if (lastOperation == MULTIPLY)
|
||||||
|
multiplyNumbers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.btn_decimal)
|
@OnClick(R.id.btn_decimal)
|
||||||
|
|
Loading…
Reference in New Issue