44import java .security .SecureRandom ;
55
66public class Calculator {
7- private static final String DESCRIPTION = "What is the result of the expression?" ;
8- private static final char [] OPERATORS = {'+' , '-' , '*' };
97
108 public static int calculate (int operand1 , int operand2 , char operator ) {
119 switch (operator ) {
@@ -21,13 +19,16 @@ public static int calculate(int operand1, int operand2, char operator) {
2119 }
2220
2321 public static void startGame () {
22+ String description = "What is the result of the expression?" ;
23+ char [] operators = {'+' , '-' , '*' };
2424 String [][] data = new String [Engine .getRoundsCount ()][2 ];
2525 SecureRandom random = new SecureRandom ();
2626
27+
2728 for (int i = 0 ; i < Engine .getRoundsCount (); i ++) {
2829 int number1 = random .nextInt (100 ) + 1 ;
2930 int number2 = random .nextInt (100 ) + 1 ;
30- char operator = OPERATORS [random .nextInt (OPERATORS .length )];
31+ char operator = operators [random .nextInt (operators .length )];
3132
3233 String question = number1 + " " + operator + " " + number2 ;
3334 String correctAnswer = String .valueOf (calculate (number1 , number2 , operator ));
@@ -36,8 +37,6 @@ public static void startGame() {
3637 data [i ][1 ] = correctAnswer ;
3738 }
3839
39- Engine .run (DESCRIPTION , data );
40+ Engine .run (description , data );
4041 }
4142}
42-
43-
0 commit comments