Skip to content

Commit c599eb7

Browse files
author
Aleksandr Pronichev
committed
fix
1 parent 5e019eb commit c599eb7

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ public static String[][] generateData() {
2323
int secondNumber = Utils.getRandomInt(MIN_NUMBER, MAX_NUMBER);
2424
char operator = operators[(int) (Math.random() * operators.length)];
2525
String question = firstNumber + " " + operator + " " + secondNumber;
26-
String correctAnswer = calculate(firstNumber, secondNumber, operator);
26+
String correctAnswer = Integer.toString(calculate(firstNumber, secondNumber, operator));
2727

2828
questionsAndAnswers[i][0] = question;
2929
questionsAndAnswers[i][1] = correctAnswer;
3030
}
3131
return questionsAndAnswers;
3232
}
3333

34-
public static String calculate(int firstNumber, int secondNumber, char operator) {
34+
public static int calculate(int firstNumber, int secondNumber, char operator) {
3535
switch (operator) {
3636
case '+':
37-
return Integer.toString(firstNumber + secondNumber);
37+
return firstNumber + secondNumber;
3838
case '-':
39-
return Integer.toString(firstNumber - secondNumber);
39+
return firstNumber - secondNumber;
4040
case '*':
41-
return Integer.toString(firstNumber * secondNumber);
41+
return firstNumber * secondNumber;
4242
default:
4343
throw new IllegalArgumentException("Unsupported operator");
4444
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public static String[][] generateData() {
1919
for (int i = 0; i < Engine.ROUNDS; i++) {
2020
int number = Utils.getRandomInt(MIN_NUMBER, MAX_NUMBER);
2121
String question = Integer.toString(number);
22-
String correctAnswer = isEven(number);
22+
String correctAnswer = isEven(number) ? "yes" : "no";
2323
questionsAndAnswers[i][0] = question;
2424
questionsAndAnswers[i][1] = correctAnswer;
2525
}
2626
return questionsAndAnswers;
2727
}
2828

29-
public static String isEven(int number) {
30-
return (number % 2 == 0) ? "yes" : "no";
29+
public static boolean isEven(int number) {
30+
return (number % 2 == 0);
3131
}
3232
}
3333

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,32 @@ public static String[][] generateData() {
2424
int start = Utils.getRandomInt(0, MAX_START);
2525
int step = Utils.getRandomInt(1, MAX_STEP + 1);
2626

27-
String[] progression = generateProgression(start, step, progressionLength);
27+
int[] progression = generateProgression(start, step, progressionLength);
2828

29-
questionsAndAnswers[i][0] = progression[0];
30-
questionsAndAnswers[i][1] = progression[1];
29+
String[] stringProgression = new String[progression.length];
30+
for (int j = 0; j < progression.length; j++) {
31+
stringProgression[j] = Integer.toString(progression[j]);
32+
}
33+
34+
int missingIndex = Utils.getRandomInt(0, progressionLength - 1);
35+
String missingNumber = stringProgression[missingIndex];
36+
stringProgression[missingIndex] = "..";
37+
38+
String question = String.join(" ", stringProgression);
39+
40+
questionsAndAnswers[i][0] = question;
41+
questionsAndAnswers[i][1] = missingNumber;
3142
}
3243
return questionsAndAnswers;
3344
}
3445

35-
public static String[] generateProgression(int start, int step, int length) {
46+
public static int[] generateProgression(int start, int step, int length) {
3647
int[] progression = new int[length];
3748

3849
for (int i = 0; i < length; i++) {
3950
progression[i] = start + i * step;
4051
}
4152

42-
int missingIndex = Utils.getRandomInt(0, length - 1);
43-
int missingNumber = progression[missingIndex];
44-
45-
String[] formattedProgression = new String[length];
46-
47-
for (int i = 0; i < length; i++) {
48-
if (i == missingIndex) {
49-
formattedProgression[i] = "..";
50-
} else {
51-
formattedProgression[i] = Integer.toString(progression[i]);
52-
}
53-
}
54-
String question = String.join(" ", formattedProgression);
55-
return new String[]{question, Integer.toString(missingNumber)};
53+
return progression;
5654
}
5755
}

0 commit comments

Comments
 (0)