| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | public class CalculatorModel { private double answer, initial_number; // Constructor sets both numbers. public CalculatorModel() { answer = 0.0; initial_number = 0.0; } // Adds a number to the existing answer. public void doAddition(double y) { answer = answer + y; } // Subtracts a number to the existing answer. public void doSubtraction(double y) { answer = answer - y; } // Multiplies the existing answer by a number. public void doMultiply(double y) { answer = answer * y; } // Divides the existing answer by a number. public void doDivision(double y) { answer = answer / y; } // Gets the current answer. public double getAnswer() { return answer; } // Sets the current answer. public void setAnswer(double new_answer) { answer = new_answer; } // Sets the initial number. public void setInitialNumber(double new_initial) { initial_number = new_initial; } // Sets the answer to be the initial number. public void reset() { answer = initial_number; } } |