-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEqualCommandButton.java
34 lines (31 loc) · 1.12 KB
/
EqualCommandButton.java
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
public class EqualCommandButton extends CommandButton {
CalcGUIV1 display;
public EqualCommandButton(Calculator calculator, CalcGUIV1 display) {
super(calculator);
this.display = display;
}
@Override
public void execute() {
int result = 0;
Calculator calculator = getCalculator();
if (calculator.isOperand1Set() && calculator.isOperand2Set() && calculator.isOperatorSet()) { // 두 개 피 연산자값과 연산자가 지정되었다면
int operand1 = calculator.getOperand1();
int operand2 = calculator.getOperand2();
char op = calculator.getOperator();
if (op == '+') {
result = operand1 + operand2;
}
else if (op == '-') {
result = operand1 - operand2;
}
else if (op == '*') {
result = operand1 * operand2;
}
else if (op == '/') {
result = operand1 / operand2;
}
}
display.showText("" + result);
calculator.clearFlags();
}
}