Skip to content

Commit 3e78aad

Browse files
committed
refactoring #1
1 parent 1653c11 commit 3e78aad

File tree

6 files changed

+10
-16
lines changed

6 files changed

+10
-16
lines changed

app/src/main/java/hexlet/code/Engine.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
public class Engine {
66
private static String name = "";
7-
8-
public static void beginGame(String rules, int rounds, String[][] questionsAndAnswers) {
7+
public static final int ROUNDS = 3;
8+
public static void beginGame(String rules, String[][] questionsAndAnswers) {
99
Scanner scanner = new Scanner(System.in);
1010
System.out.println("\nWelcome to the Brain Games!");
1111
System.out.print("May I have your name? ");
@@ -14,7 +14,7 @@ public static void beginGame(String rules, int rounds, String[][] questionsAndAn
1414
System.out.println(rules);
1515
int counterRightAnswers = 0;
1616

17-
for (int i = 0; counterRightAnswers < rounds; i++) {
17+
for (int i = 0; counterRightAnswers < ROUNDS; i++) {
1818
System.out.println("Question: " + questionsAndAnswers[i][0]);
1919
System.out.print("Your answer: ");
2020
String userAnswer = scanner.next();
@@ -30,7 +30,7 @@ public static void beginGame(String rules, int rounds, String[][] questionsAndAn
3030
System.exit(0);
3131
}
3232
}
33-
if (counterRightAnswers == rounds) {
33+
if (counterRightAnswers == ROUNDS) {
3434
System.out.println("Congratulations, " + name + "!");
3535
System.exit(0);
3636
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
public class Calc {
77
static final int MAX_RANDOM_INT = 100;
8-
private static final int ROUNDS = 3;
98
public static final String RULES = "What is the result of the expression?";
109

1110
public static void start() {
12-
Engine.beginGame(RULES, ROUNDS, getQandA(ROUNDS));
11+
Engine.beginGame(RULES, getQandA(Engine.ROUNDS));
1312
}
1413

1514
private static char getRandomOperator() {
@@ -20,9 +19,7 @@ private static char getRandomOperator() {
2019

2120
public static String[][] getQandA(int rounds) {
2221
String[][] qAndA = new String[rounds][rounds];
23-
2422
for (int i = 0; i < rounds; i++) {
25-
2623
int randomNumber1 = Utils.randomIntGenerator(MAX_RANDOM_INT);
2724
int randomNumber2 = Utils.randomIntGenerator(MAX_RANDOM_INT);
2825
char randomOperator = getRandomOperator();

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

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

66
public class Even {
7-
private static final int ROUNDS = 3;
87
public static final int MIN_RANDOM_INT = 1;
98
public static final int MAX_RANDOM_INT = 200;
109
public static final String RULES = "Answer 'yes' if the number is even, otherwise answer 'no'.";
1110

1211
public static void start() {
13-
Engine.beginGame(RULES, ROUNDS, getQandA(ROUNDS));
12+
Engine.beginGame(RULES, getQandA(Engine.ROUNDS));
1413
}
1514

1615
public static String[][] getQandA(int rounds) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
public class GCD {
77
static final int MAX_RANDOM_INT = 100;
8-
private static final int ROUNDS = 3;
98
public static final String RULES = "Find the greatest common divisor of given numbers.";
109

1110
public static void start() {
12-
Engine.beginGame(RULES, ROUNDS, getQandA(ROUNDS));
11+
Engine.beginGame(RULES, getQandA(Engine.ROUNDS));
1312
}
1413

1514
public static int getGCD(int a, int b) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
public class Prime {
77
public static final int MIN_RANDOM_INT = 1;
88
public static final int MAX_RANDOM_INT = 200;
9-
private static final int ROUNDS = 3;
109
public static final String RULES = "Answer 'yes' if given number is prime. Otherwise answer 'no'.";
1110

1211
public static void start() {
13-
Engine.beginGame(RULES, ROUNDS, getQandA(ROUNDS));
12+
Engine.beginGame(RULES, getQandA(Engine.ROUNDS));
1413
}
1514

1615
public static boolean isPrime(int n) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public class Progression {
1010
public static final int MAX_ADDITION_INT_BOUND = 50;
1111
public static final int MIN_HIDDEN_INDEX = 1;
1212
public static final int NUMBER_OF_ITEMS_IN_QUESTION = 10;
13-
private static final int ROUNDS = 3;
1413
public static final String RULES = "What number is missing in the progression?";
1514

1615
public static void start() {
17-
Engine.beginGame(RULES, ROUNDS, getQandA(ROUNDS)); }
16+
Engine.beginGame(RULES, getQandA(Engine.ROUNDS));
17+
}
1818

1919
public static String[][] getQandA(int rounds) {
2020
String[][] qAndA = new String[rounds][rounds];

0 commit comments

Comments
 (0)