Skip to content

Commit 08f0331

Browse files
committed
excluding maging numbers
1 parent c500ab9 commit 08f0331

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

app/src/main/java/hexlet/code/games/Calculator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.security.SecureRandom;
55

66
public class Calculator {
7+
static final int NUMBERS_COUNT = 100;
78

89
public static int calculate(int operand1, int operand2, char operator) {
910
switch (operator) {
@@ -25,10 +26,9 @@ public static void startGame() {
2526
SecureRandom random = new SecureRandom();
2627

2728
for (int i = 0; i < Engine.getRoundsCount(); i++) {
28-
int numbersCount = 100;
2929

30-
int number1 = random.nextInt(numbersCount) + 1;
31-
int number2 = random.nextInt(numbersCount) + 1;
30+
int number1 = random.nextInt(NUMBERS_COUNT) + 1;
31+
int number2 = random.nextInt(NUMBERS_COUNT) + 1;
3232
char operator = operators[random.nextInt(operators.length)];
3333

3434
String question = number1 + " " + operator + " " + number2;

app/src/main/java/hexlet/code/games/Even.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
import java.security.SecureRandom;
55

66
public class Even {
7+
static final int NUMBERS_COUNT = 100;
8+
79
public static void startGame() {
810
String description = "Answer 'yes' if the number is even, otherwise answer 'no'.";
911
String[][] data = new String[Engine.getRoundsCount()][2];
1012
SecureRandom random = new SecureRandom();
1113

1214

1315
for (int i = 0; i < Engine.getRoundsCount(); i++) {
14-
int numbersCount = 100;
1516

16-
int number = random.nextInt(numbersCount) + 1;
17+
int number = random.nextInt(NUMBERS_COUNT) + 1;
1718
String question = String.valueOf(number);
1819
String correctAnswer = number % 2 == 0 ? "yes" : "no";
1920

app/src/main/java/hexlet/code/games/Gcd.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.security.SecureRandom;
55

66
public class Gcd {
7-
7+
static final int NUMBERS_COUNT = 100;
88

99
private static int isGCD(int a, int b) {
1010
while (b != 0) {
@@ -21,10 +21,9 @@ public static void startGame() {
2121
SecureRandom random = new SecureRandom();
2222

2323
for (int i = 0; i < Engine.getRoundsCount(); i++) {
24-
int numbersCount = 100;
2524

26-
int number1 = random.nextInt(numbersCount) + 1;
27-
int number2 = random.nextInt(numbersCount) + 1;
25+
int number1 = random.nextInt(NUMBERS_COUNT) + 1;
26+
int number2 = random.nextInt(NUMBERS_COUNT) + 1;
2827
String question = number1 + " " + number2;
2928
String correctAnswer = String.valueOf(isGCD(number1, number2));
3029

app/src/main/java/hexlet/code/games/Prime.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.security.SecureRandom;
55

66
public class Prime {
7+
static final int NUMBERS_COUNT = 100;
8+
79
public static boolean isPrime(int number) {
810
if (number < 2) {
911
return false;
@@ -22,9 +24,8 @@ public static void startGame() {
2224
SecureRandom random = new SecureRandom();
2325

2426
for (int i = 0; i < Engine.getRoundsCount(); i++) {
25-
int numbersCount = 100;
2627

27-
int number = random.nextInt(numbersCount) + 1;
28+
int number = random.nextInt(NUMBERS_COUNT) + 1;
2829
String question = String.valueOf(number);
2930
String correctAnswer = isPrime(number) ? "yes" : "no";
3031

app/src/main/java/hexlet/code/games/Progression.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import java.security.SecureRandom;
55

66
public class Progression {
7+
static final int START_NUMBER = 60;
8+
static final int STEP_NUMBER = 10;
9+
static final int HIDDEN_NUMBER = 10;
10+
static final int LENGTH = 10;
11+
712
public static String[] generateProgression(int start, int step, int length) {
813
String[] progression = new String[length];
914
for (int index = 0; index < length; index++) {
@@ -20,16 +25,12 @@ public static void startGame() {
2025

2126

2227
for (int i = 0; i < Engine.getRoundsCount(); i++) {
23-
int startNumber = 60;
24-
int stepNumber = 10;
25-
int hiddenNumber = 10;
26-
int length = 10;
2728

28-
int start = random.nextInt(startNumber) + 1;
29-
int step = random.nextInt(stepNumber) + 1;
30-
int hiddenIndex = random.nextInt(hiddenNumber);
29+
int start = random.nextInt(START_NUMBER) + 1;
30+
int step = random.nextInt(STEP_NUMBER) + 1;
31+
int hiddenIndex = random.nextInt(HIDDEN_NUMBER);
3132

32-
String[] progression = generateProgression(start, step, length);
33+
String[] progression = generateProgression(start, step, LENGTH);
3334
String correctAnswer = progression[hiddenIndex];
3435
progression[hiddenIndex] = "..";
3536

0 commit comments

Comments
 (0)