Created
October 10, 2019 15:43
-
-
Save BMU-Verlag/a4a0e36c1d19775a6d95e19747d966d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FXML | |
private void evaluate() { | |
if (nextOperation == Operation.none) { | |
input.setText(""); | |
lastResult.setText(""); | |
return; | |
} | |
var lastResultFloat = Float.parseFloat(lastResult.getText()); | |
var inputFloat = Float.parseFloat(input.getText()); | |
var result = 0f; | |
switch (nextOperation) { | |
case ADD: | |
result = lastResultFloat + inputFloat; | |
break; | |
case SUBTRACT: | |
result = lastResultFloat - inputFloat; | |
break; | |
case MULTIPLY: | |
result = lastResultFloat * inputFloat; | |
break; | |
case DIVIDE: | |
if (inputFloat == 0) { | |
lastResult.setText("Error"); | |
input.setText(""); | |
nextOperation = Operation.NONE; | |
return; | |
} | |
result = lastResultFloat / inputFloat; | |
break; | |
default: | |
return; | |
} | |
input.setText(""); | |
lastResult.setText(String.valueOf(result)); | |
nextOperation = Operation.none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment