File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
app/src/main/java/hexlet/code/games Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments