Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Calculator
- {
- private int firstOperand, secondOperand, operator, display;
- public static final void int PLUS = 1;
- public static final void int MINUS = 2;
- public static final void int TIMES = 3;
- public static final void int DIVIDE = 4;
- public static final void int EQUALS = 0;
- public static final void int NONE = -1;
- public Calculator()
- {
- display = 0;
- firstOperand = 0;
- secondOperand = 0;
- operator = NONE;
- }
- /*pre: digit >= 0 && digit <= 9*/
- public int numberkey (int key)
- {
- if (operand == NONE)
- {
- firstOperand = firstOperand*10 + key;
- display = firstOperand;
- }
- el
- else if (operand > 0)
- else if (operand == EQUALS)
- display = firstOperand;
- }
- public int plus()
- {
- return firsOperand = firstOperand *10 + secondOperand;
- }
- public int minus()
- {
- return ;
- }
- public int divide()
- {
- return ;
- }
- public int times()
- {
- return ;
- }
- public int equals()
- {
- if (operator == PLUS)
- firstOperand = firstOperand + secondOperand;
- else if (operator == MINUS)
- firstOperand = firstOperand - secondOperand;
- else if (operator == TIMES)
- firstOperand = firstOperand*secondOperand;
- else if (operator == DIVIDE)
- firstOperand = firstOperand/secondOperand;
- /*if (operator == PLUS)
- firstOperand = firstOperand + secondOperand;
- else
- if (operator == MINUS)
- firstOperand = firstOperand - secondOperand;
- else
- if (operator == TIMES)
- firstOperand = firstOperand*secondOperand;
- else
- if (operator == DIVIDE)
- firstOperand = firstOperand/secondOperand;*/
- display = firstOperand;
- secondOperand = 0;
- operator = EQUALS;
- return display;
- }
- public int clear(){return EQUALS;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement