File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
app/src/main/java/hexlet/code Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 1+ package hexlet .code ;
2+
3+ import java .util .Random ;
4+
5+ public class Utils {
6+ public static int getRandomInt (int minNumber , int maxNumber ) {
7+ Random random = new Random ();
8+ int randomNumber = random .nextInt (maxNumber - minNumber + 1 ) + minNumber ;
9+ return randomNumber ;
10+ }
11+ }
Original file line number Diff line number Diff line change 11package hexlet .code .games ;
22
33import hexlet .code .Engine ;
4+ import hexlet .code .Utils ;
45
56public class Even {
67
78 private static final String RULES = "Answer 'yes' if the number is even, otherwise answer 'no'." ;
9+ private static final int MIN_NUMBER = 1 ;
810 private static final int MAX_NUMBER = 100 ;
911
1012 public static void gameEven () {
@@ -15,13 +17,17 @@ public static void gameEven() {
1517 public static String [][] generateData () {
1618 String [][] questionsAndAnswers = new String [Engine .ROUNDS ][2 ];
1719 for (int i = 0 ; i < Engine .ROUNDS ; i ++) {
18- int number = ( int ) ( Math . random () * MAX_NUMBER );
20+ int number = Utils . getRandomInt ( MIN_NUMBER , MAX_NUMBER );
1921 String question = Integer .toString (number );
20- String correctAnswer = (number % 2 == 0 ) ? "yes" : "no" ;
22+ String correctAnswer = isEven (number ) ;
2123 questionsAndAnswers [i ][0 ] = question ;
2224 questionsAndAnswers [i ][1 ] = correctAnswer ;
2325 }
2426 return questionsAndAnswers ;
2527 }
28+
29+ public static String isEven (int number ) {
30+ return (number % 2 == 0 ) ? "yes" : "no" ;
31+ }
2632}
2733
You can’t perform that action at this time.
0 commit comments