A
androidcoder
Neues Mitglied
- 0
Hallo,
Wozu bzw. für was ist die Variable pendingOperation da?
Wozu brauchen wir diese zwei Code Snippet hier? Was wird hier gemacht?
1)
2)
Ganzer Code:
Vielen Dank für eure Hilfe
Wozu bzw. für was ist die Variable pendingOperation da?
Wozu brauchen wir diese zwei Code Snippet hier? Was wird hier gemacht?
1)
Code:
if (pendingOperation.equals("=")) {
pendingOperation = operation;
}
2)
Code:
switch (pendingOperation) {
case "=":
operand1 = operand2;
break;
Ganzer Code:
Code:
private void performOperation(String value, String operation){
if (null == operand1) {
operand1 = Double.valueOf(value);
} else {
operand2 = Double.valueOf(value);
if (pendingOperation.equals("=")) {
pendingOperation = operation;
}
switch (pendingOperation) {
case "=":
operand1 = operand2;
break;
case "/":
if (operand2 == 0) {
operand1 = 0.0;
} else {
operand1 /= operand2;
}
break;
case "*":
operand1 *= operand2;
break;
case "-":
operand1 -= operand2;
break;
case "+":
operand1 += operand2;
break;
}
}
result.setText(operand1.toString());
newNumber.setText("");
}
Vielen Dank für eure Hilfe