Skip to content

Commit 995e1bb

Browse files
committed
refactor: calculations are placed in separate methods
1 parent 992c4ba commit 995e1bb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

app/src/main/java/hexlet/code/games/Calc.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,8 @@ public static void startGame() {
1515

1616
String question = num1 + " " + mathSymbol + " " + num2;
1717

18-
int result = switch (mathSymbol) {
19-
case '+' -> num1 + num2;
20-
case '-' -> num1 - num2;
21-
case '*' -> num1 * num2;
22-
default -> 0;
23-
};
24-
2518
roundsData[i][0] = question;
26-
roundsData[i][1] = String.valueOf(result);
19+
roundsData[i][1] = String.valueOf(getExpressionResult(mathSymbol, num1, num2));
2720
}
2821
Engine.run(description, roundsData);
2922
}
@@ -33,4 +26,13 @@ private static char getRandomMathSymbol() {
3326
int index = Utils.generateNumber(0, 2);
3427
return mathSymbols[index];
3528
}
29+
30+
private static int getExpressionResult(char mathSymbol, int numOne, int numTwo) {
31+
return switch (mathSymbol) {
32+
case '+' -> numOne + numTwo;
33+
case '-' -> numOne - numTwo;
34+
case '*' -> numOne * numTwo;
35+
default -> 0;
36+
};
37+
}
3638
}

0 commit comments

Comments
 (0)