File tree Expand file tree Collapse file tree 6 files changed +23
-20
lines changed
app/src/main/java/hexlet/code Expand file tree Collapse file tree 6 files changed +23
-20
lines changed Original file line number Diff line number Diff line change 11package hexlet .code ;
22
33public class Utils {
4- //границы случайных чисел не были обозначены сделал от 1 до 100. требуется уточнение у аналитика
5- public static final int MIN_NUMBER = 1 ;
6- public static final int MAX_NUMBER = 100 ;
74
85 public static int generateNumber (int min , int max ) {
96 return (int ) Math .floor (Math .random () * (max - min + 1 )) + min ;
107 }
118
12- public static int generateNumber () {
13- return generateNumber (MIN_NUMBER , MAX_NUMBER );
14- }
159}
Original file line number Diff line number Diff line change 44import hexlet .code .Utils ;
55
66public class Calc {
7+ public static final int MIN_NUMBER = 1 ;
8+ public static final int MAX_NUMBER = 100 ;
9+
710 public static void play () {
811 String optionDescription = "What is the result of the expression?" ;
912 String [][] questionsAndCorrectAnswers = new String [Engine .ROUNDS ][2 ];
1013
1114 for (int i = 0 ; i < Engine .ROUNDS ; i ++) {
12- int firstValue = Utils .generateNumber ();
13- int secondValue = Utils .generateNumber ();
15+ int firstValue = Utils .generateNumber (MIN_NUMBER , MAX_NUMBER );
16+ int secondValue = Utils .generateNumber (MIN_NUMBER , MAX_NUMBER );
1417 char [] signs = {'+' , '-' , '*' };
1518 char randomSign = signs [Utils .generateNumber (0 , signs .length - 1 )];
1619
Original file line number Diff line number Diff line change 44import hexlet .code .Utils ;
55
66public class Even {
7+ public static final int MIN_NUMBER = 1 ;
8+ public static final int MAX_NUMBER = 100 ;
9+
710 public static void play () {
811 String optionDescription = "Answer 'yes' if the number is even, otherwise answer 'no'." ;
912 String [][] questionsAndCorrectAnswers = new String [Engine .ROUNDS ][2 ];
1013
1114 for (int i = 0 ; i < Engine .ROUNDS ; i ++) {
12- int random = Utils .generateNumber ();
15+ int random = Utils .generateNumber (MIN_NUMBER , MAX_NUMBER );
1316 String question = String .valueOf (random );
1417 boolean isEven = random % 2 == 0 ;
1518 String correctAnswer = isEven ? "yes" : "no" ;
Original file line number Diff line number Diff line change 44import hexlet .code .Utils ;
55
66public class Gcd {
7+ public static final int MIN_NUMBER = 1 ;
8+ public static final int MAX_NUMBER = 100 ;
9+
710 public static void play () {
811 String optionDescription = "Find the greatest common divisor of given numbers." ;
912 String [][] questionsAndCorrectAnswers = new String [Engine .ROUNDS ][2 ];
1013
1114 for (int i = 0 ; i < Engine .ROUNDS ; i ++) {
12- int firstValue = Utils .generateNumber ();
13- int secondValue = Utils .generateNumber ();
15+ int firstValue = Utils .generateNumber (MIN_NUMBER , MAX_NUMBER );
16+ int secondValue = Utils .generateNumber (MIN_NUMBER , MAX_NUMBER );
1417
1518 String question = firstValue + " " + secondValue ;
1619 String correctAnswer = String .valueOf (gcd (firstValue , secondValue ));
Original file line number Diff line number Diff line change 44import hexlet .code .Utils ;
55
66public class Prime {
7+ public static final int MIN_NUMBER = 1 ;
8+ public static final int MAX_NUMBER = 100 ;
9+
710 public static void play () {
811 String optionDescription = "Answer 'yes' if given number is prime. Otherwise answer 'no'." ;
912 String [][] questionsAndCorrectAnswers = new String [Engine .ROUNDS ][2 ];
1013
1114 for (int i = 0 ; i < Engine .ROUNDS ; i ++) {
12- int random = Utils .generateNumber ();
15+ int random = Utils .generateNumber (MIN_NUMBER , MAX_NUMBER );
1316
1417 String question = String .valueOf (random );
15- String correctAnswer ;
16- if (isPrime (random )) {
17- correctAnswer = "yes" ;
18- } else {
19- correctAnswer = "no" ;
20- }
18+ String correctAnswer = isPrime (random ) ? "yes" : "no" ;
2119
2220 questionsAndCorrectAnswers [i ][0 ] = question ;
2321 questionsAndCorrectAnswers [i ][1 ] = correctAnswer ;
Original file line number Diff line number Diff line change 44import hexlet .code .Utils ;
55
66public class Progression {
7+ public static final int MIN_NUMBER = 1 ;
8+ public static final int MAX_NUMBER = 100 ;
79 private static final int STEP_COUNT = 10 ;
810 private static final int VALUE_COUNT = 10 ;
911
@@ -12,8 +14,8 @@ public static void play() {
1214 String [][] questionsAndCorrectAnswers = new String [Engine .ROUNDS ][2 ];
1315
1416 for (int i = 0 ; i < Engine .ROUNDS ; i ++) {
15- int start = Utils .generateNumber ();
16- int step = Utils .generateNumber (Utils . MIN_NUMBER , STEP_COUNT );
17+ int start = Utils .generateNumber (MIN_NUMBER , MAX_NUMBER );
18+ int step = Utils .generateNumber (MIN_NUMBER , STEP_COUNT );
1719 int hideIndex = Utils .generateNumber (0 , VALUE_COUNT - 1 );
1820
1921 String [] sequence = addSequence (start , step , VALUE_COUNT );
You can’t perform that action at this time.
0 commit comments