Skip to content

Commit 45e70b5

Browse files
committed
refactor: creating constants for methods
1 parent cd67e8c commit 45e70b5

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import hexlet.code.Utils;
55

66
public class Calc {
7+
private static final int MIN = 0;
8+
private static final int MAX = 100;
79
public static void startGame() {
810
String[][] roundsData = new String[Engine.ROUNDS][2];
911
String description = "What is the result of the expression?";
1012

1113
for (int i = 0; i < Engine.ROUNDS; i++) {
12-
int num1 = Utils.generateNumber(0, 100);
13-
int num2 = Utils.generateNumber(0, 100);
14+
int num1 = Utils.generateNumber(MIN, MAX);
15+
int num2 = Utils.generateNumber(MIN, MAX);
1416
char mathSymbol = getRandomMathSymbol();
1517

1618
String question = num1 + " " + mathSymbol + " " + num2;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import hexlet.code.Utils;
55

66
public class Even {
7+
private static final int MIN = 0;
8+
private static final int MAX = 100;
79
public static void startGame() {
10+
811
String description = "Answer 'yes' if the number is even, otherwise answer 'no'.";
912
String[][] roundsData = new String[Engine.ROUNDS][2];
1013

1114
for (int i = 0; i < Engine.ROUNDS; i++) {
12-
int question = Utils.generateNumber(1, 100);
15+
int question = Utils.generateNumber(MIN, MAX);
1316
String answer = (question % 2 == 0) ? "yes" : "no";
1417
roundsData[i][0] = String.valueOf(question);
1518
roundsData[i][1] = answer;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
import hexlet.code.Utils;
55

66
public class GCD {
7+
private static final int MIN = 0;
8+
private static final int MAX = 100;
79
public static void startGame() {
10+
811
String[][] roundsData = new String[Engine.ROUNDS][2];
912
String description = "Find the greatest common divisor of given numbers.";
1013

1114
for (int i = 0; i < Engine.ROUNDS; i++) {
12-
int num1 = Utils.generateNumber(0, 100);
13-
int num2 = Utils.generateNumber(0, 100);
15+
int num1 = Utils.generateNumber(MIN, MAX);
16+
int num2 = Utils.generateNumber(MIN, MAX);
1417
String question = num1 + " " + num2;
1518
int result = gcdCalculate(num1, num2);
1619
roundsData[i][0] = question;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import hexlet.code.Utils;
55

66
public class Prime {
7+
private static final int MIN = 2;
8+
private static final int MAX = 1000;
79
public static void startGame() {
810

911
String[][] roundsData = new String[Engine.ROUNDS][2];
1012
String description = "Answer 'yes' if given number is prime. Otherwise answer 'no'.";
1113

1214
for (int i = 0; i < Engine.ROUNDS; i++) {
13-
int num = Utils.generateNumber(2,1000);
15+
int num = Utils.generateNumber(MIN, MAX);
1416
String answer = isPrime(num) ? "yes" : "no";
1517
roundsData[i][0] = String.valueOf(num);
1618
roundsData[i][1] = answer;

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@
44
import hexlet.code.Utils;
55

66
public class Progression {
7+
private static final int PROGRESSION_LENGTH = 10;
8+
private static final int STEP_MIN = 1;
9+
private static final int STEP_MAX = 10;
10+
private static final int FIRST_NUM_MIN = 1;
11+
private static final int FIRST_NUM_MAX = 100;
12+
private static final int HIDDEN_MIN = 1;
13+
private static final int HIDDEN_MAX = 10;
714
public static void startGame() {
8-
final int PROGRESSION_LENGTH = 10;
15+
16+
917
String[][] roundsData = new String[Engine.ROUNDS][2];
1018
String description = "What number is missing in the progression?";
1119

1220
for (int i = 0; i < Engine.ROUNDS; i++) {
1321
String[] progression = makeProgression(
14-
Utils.generateNumber(1, 100),
15-
Utils.generateNumber(1, 10), PROGRESSION_LENGTH);
16-
int hiddenMemberIndex = Utils.generateNumber(0, 9);
22+
Utils.generateNumber(FIRST_NUM_MIN, FIRST_NUM_MAX),
23+
Utils.generateNumber(STEP_MIN, STEP_MAX), PROGRESSION_LENGTH);
24+
int hiddenMemberIndex = Utils.generateNumber(HIDDEN_MIN, HIDDEN_MAX);
1725
String answer = progression[hiddenMemberIndex];
1826

1927
progression[hiddenMemberIndex] = "..";

0 commit comments

Comments
 (0)