change operation constants to strings
This commit is contained in:
parent
920b8f87a6
commit
1969300620
3 changed files with 23 additions and 23 deletions
|
@ -6,8 +6,8 @@ public class CalculatorImpl {
|
|||
private double baseValue;
|
||||
private double secondValue;
|
||||
private boolean resetValue;
|
||||
private int lastKey;
|
||||
private int lastOperation;
|
||||
private String lastKey;
|
||||
private String lastOperation;
|
||||
private Calculator callback;
|
||||
|
||||
public CalculatorImpl(Calculator calculatorInterface) {
|
||||
|
@ -26,12 +26,12 @@ public class CalculatorImpl {
|
|||
baseValue = 0;
|
||||
secondValue = 0;
|
||||
resetValue = false;
|
||||
lastKey = 0;
|
||||
lastOperation = 0;
|
||||
lastKey = "";
|
||||
lastOperation = "";
|
||||
callback.setValue("0");
|
||||
}
|
||||
|
||||
public void setLastKey(int lastKey) {
|
||||
public void setLastKey(String lastKey) {
|
||||
this.lastKey = lastKey;
|
||||
}
|
||||
|
||||
|
@ -116,18 +116,18 @@ public class CalculatorImpl {
|
|||
updateResult(resultValue);
|
||||
}
|
||||
|
||||
public void handleOperation(int operation) {
|
||||
if (lastKey == operation)
|
||||
public void handleOperation(String operation) {
|
||||
if (lastKey.equals(operation))
|
||||
return;
|
||||
|
||||
if (lastKey == Constants.DIGIT)
|
||||
if (lastKey.equals(Constants.DIGIT))
|
||||
handleResult();
|
||||
|
||||
resetValue = true;
|
||||
lastKey = operation;
|
||||
lastOperation = operation;
|
||||
|
||||
if (operation == Constants.ROOT)
|
||||
if (operation.equals(Constants.ROOT))
|
||||
calculateResult();
|
||||
}
|
||||
|
||||
|
@ -156,10 +156,10 @@ public class CalculatorImpl {
|
|||
}
|
||||
|
||||
public void handleEquals() {
|
||||
if (lastKey == Constants.EQUALS)
|
||||
if (lastKey.equals(Constants.EQUALS))
|
||||
calculateResult();
|
||||
|
||||
if (lastKey != Constants.DIGIT)
|
||||
if (!lastKey.equals(Constants.DIGIT))
|
||||
return;
|
||||
|
||||
secondValue = getDisplayedNumberAsDouble();
|
||||
|
@ -182,7 +182,7 @@ public class CalculatorImpl {
|
|||
}
|
||||
|
||||
public void numpadClicked(View view) {
|
||||
if (lastKey == Constants.EQUALS)
|
||||
if (lastKey.equals(Constants.EQUALS))
|
||||
lastOperation = Constants.EQUALS;
|
||||
lastKey = Constants.DIGIT;
|
||||
resetValueIfNeeded();
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package calculator.simplemobiletools.com.simple_calculator;
|
||||
|
||||
public class Constants {
|
||||
public static final int DIGIT = 0;
|
||||
public static final int EQUALS = 1;
|
||||
public static final int PLUS = 2;
|
||||
public static final int MINUS = 3;
|
||||
public static final int MULTIPLY = 4;
|
||||
public static final int DIVIDE = 5;
|
||||
public static final int MODULO = 6;
|
||||
public static final int POWER = 7;
|
||||
public static final int ROOT = 8;
|
||||
public static final String DIGIT = "digit";
|
||||
public static final String EQUALS = "equals";
|
||||
public static final String PLUS = "plus";
|
||||
public static final String MINUS = "minus";
|
||||
public static final String MULTIPLY = "multiply";
|
||||
public static final String DIVIDE = "divide";
|
||||
public static final String MODULO = "modulo";
|
||||
public static final String POWER = "power";
|
||||
public static final String ROOT = "root";
|
||||
}
|
||||
|
|
|
@ -148,11 +148,11 @@ public class MainActivityTest {
|
|||
activity.setValueDouble(d);
|
||||
}
|
||||
|
||||
private void handleOperation(int operation) {
|
||||
private void handleOperation(String operation) {
|
||||
activity.getCalc().handleOperation(operation);
|
||||
}
|
||||
|
||||
private String calcResult(double baseValue, int operation, double secondValue) {
|
||||
private String calcResult(double baseValue, String operation, double secondValue) {
|
||||
setDouble(baseValue);
|
||||
handleOperation(operation);
|
||||
setDouble(secondValue);
|
||||
|
|
Loading…
Reference in a new issue