public class Context { String first=""; String second=""; String finalResult; String operation; public void setNumber(int number) { if (operation == null) { first += Integer.toString(number); setDisplay(first); } else if (first != null && operation != null ){ second += Integer.toString(number); setDisplay(second); } } public void setOperation(String operation) { if (operation.equals("=")) { calculate(); } this.operation = operation; } public void calculate() { int firstInt = Integer.parseInt(first); int secondInt = Integer.parseInt(second); int resultInt = 0; if (operation.equals("+")) { resultInt += firstInt+secondInt; } setDisplay(Integer.toString(resultInt)); } public void setDisplay(String s ){ finalResult = s; } }
Why finalResult = null ??