@@ -16,25 +16,37 @@ private static int[] generateProgression(int length, int start, int step) {
1616 return numbers ;
1717 }
1818
19- private static String [] getQuestionAndAnswer () {
20- int randomLength = Utils .getRandomNumber (MIN_LENGTH , MAX_LENGTH );
21- int step = Utils .getRandomNumber ();
22- int startNumber = Utils .getRandomNumber ();
23-
24- int [] numbers = generateProgression (randomLength , startNumber , step );
25-
26- int randomIndex = Utils .getRandomNumber (0 , randomLength - 1 );
27- String correctAnswer = String .valueOf (numbers [randomIndex ]);
28- numbers [randomIndex ] = -1 ;
29- String question = String .join (" " , java .util .Arrays .stream (numbers )
30- .mapToObj (num -> num == -1 ? ".." : String .valueOf (num ))
31- .toArray (String []::new ));
32-
33- return new String [] {question .trim (), correctAnswer };
19+ private static String [][] getQuestionAndAnswer () {
20+ String [][] pair = new String [Engine .COUNT_OF_ROUNDS ][2 ];
21+
22+ for (int i = 0 ; i < Engine .COUNT_OF_ROUNDS ; i ++) {
23+ int randomLength = Utils .getRandomNumber (MIN_LENGTH , MAX_LENGTH );
24+ int step = Utils .getRandomNumber ();
25+ int startNumber = Utils .getRandomNumber ();
26+
27+ int [] numbers = generateProgression (randomLength , startNumber , step );
28+
29+ int randomIndex = Utils .getRandomNumber (0 , randomLength - 1 );
30+ String correctAnswer = String .valueOf (numbers [randomIndex ]);
31+
32+ StringBuilder questionBuilder = new StringBuilder ();
33+ for (int j = 0 ; j < numbers .length ; j ++) {
34+ if (j == randomIndex ) {
35+ questionBuilder .append (".. " );
36+ } else {
37+ questionBuilder .append (numbers [j ]).append (" " );
38+ }
39+ }
40+ String question = questionBuilder .toString ();
41+ pair [i ][0 ] = question ;
42+ pair [i ][1 ] = correctAnswer ;
43+ }
44+ return pair ;
3445 }
3546
3647 public static void playProgression () {
3748 String exercise = "What number is missing in the progression?" ;
38- Engine .runGame (exercise , Progression ::getQuestionAndAnswer );
49+ String [][] questionAndAnswerPairs = getQuestionAndAnswer ();
50+ Engine .runGame (exercise , questionAndAnswerPairs );
3951 }
4052}
0 commit comments