Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. public class Calculator
  2. {
  3. private int firstOperand, secondOperand, operator, display;
  4.  
  5. public static final void int PLUS = 1;
  6. public static final void int MINUS = 2;
  7. public static final void int TIMES = 3;
  8. public static final void int DIVIDE = 4;
  9. public static final void int EQUALS = 0;
  10. public static final void int NONE = -1;
  11.  
  12. public Calculator()
  13. {
  14. display = 0;
  15. firstOperand = 0;
  16. secondOperand = 0;
  17. operator = NONE;
  18. }
  19.  
  20. /*pre: digit >= 0 && digit <= 9*/
  21. public int numberkey (int key)
  22. {
  23. if (operand == NONE)
  24. {
  25. firstOperand = firstOperand*10 + key;
  26. display = firstOperand;
  27. }
  28. el
  29. else if (operand > 0)
  30.  
  31.  
  32.  
  33. else if (operand == EQUALS)
  34. display = firstOperand;
  35.  
  36. }
  37.  
  38. public int plus()
  39. {
  40. return firsOperand = firstOperand *10 + secondOperand;
  41. }
  42.  
  43. public int minus()
  44. {
  45. return ;
  46. }
  47.  
  48. public int divide()
  49. {
  50. return ;
  51. }
  52.  
  53. public int times()
  54. {
  55. return ;
  56. }
  57.  
  58. public int equals()
  59. {
  60.  
  61. if (operator == PLUS)
  62. firstOperand = firstOperand + secondOperand;
  63.  
  64. else if (operator == MINUS)
  65. firstOperand = firstOperand - secondOperand;
  66.  
  67. else if (operator == TIMES)
  68. firstOperand = firstOperand*secondOperand;
  69.  
  70. else if (operator == DIVIDE)
  71. firstOperand = firstOperand/secondOperand;
  72.  
  73. /*if (operator == PLUS)
  74. firstOperand = firstOperand + secondOperand;
  75.  
  76. else
  77. if (operator == MINUS)
  78. firstOperand = firstOperand - secondOperand;
  79.  
  80. else
  81. if (operator == TIMES)
  82. firstOperand = firstOperand*secondOperand;
  83.  
  84. else
  85. if (operator == DIVIDE)
  86. firstOperand = firstOperand/secondOperand;*/
  87. display = firstOperand;
  88. secondOperand = 0;
  89. operator = EQUALS;
  90. return display;
  91. }
  92.  
  93. public int clear(){return EQUALS;}
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement