Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public class CalculatorEngine {
  2.  
  3. private int value;
  4. private int keep;
  5. private char toDo;
  6.  
  7. void binaryOperation(char op){
  8. keep = value;
  9. value = 0;
  10. toDo = op;
  11. }
  12.  
  13. void add(){
  14. binaryOperation('+');
  15. }
  16.  
  17. void subtract(){
  18. binaryOperation('-');
  19. }
  20.  
  21. void multiply(){
  22. binaryOperation('*');
  23. }
  24.  
  25. void divide(){
  26. binaryOperation('/');
  27. }
  28.  
  29. void compute(){
  30. if(toDo == '+')
  31. value = keep + value;
  32. else if (toDo == '-' )
  33. value = keep - value;
  34. else if(toDo == '*')
  35. value = keep * value;
  36. else if(toDo == '/')
  37. value = keep / value;
  38. keep = 0;
  39. }
  40.  
  41. void clear(){
  42. value = 0;
  43. keep = 0;
  44. }
  45.  
  46. void digit(int x){
  47. value = value*10 + x;
  48. }
  49.  
  50. int display(){
  51. return value;
  52. }
  53.  
  54. CalculatorEngine(){
  55. clear();
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement