Skip to content

Commit 2c6d359

Browse files
committed
upd: linter bug fix
1 parent b559859 commit 2c6d359

File tree

6 files changed

+47
-31
lines changed

6 files changed

+47
-31
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static void gameLogic() {
1212
char[] mathSymbols = {'+', '-', '*'};
1313
int result = 0;
1414
System.out.println("What is the result of the expression?\n");
15-
while (Engine.questionCounter != Engine.MAX_QUESTIONS) {
15+
while (Engine.getQuestionCounter() != Engine.getMaxQuestions()) {
1616
Random randNum = new Random();
1717
int randMathSymbol = randNum.nextInt(mathSymbolMax);
1818
int num1 = randNum.nextInt(rndMax);
@@ -27,16 +27,16 @@ public static void gameLogic() {
2727
int answer = sc.nextInt();
2828
if (answer == result) {
2929
System.out.println("Correct!\n");
30-
Engine.questionCounter++;
30+
Engine.incrementQuestionsCounter();
3131
} else {
3232
System.out.println("Your answer: " + answer);
3333
System.out.println("'" + answer + "'" + "is wrong answer ;(. "
3434
+ "Correct answer was" + "'" + result + "'");
35-
System.out.println("Let's try again, " + Engine.userName + "!");
35+
System.out.println("Let's try again, " + Engine.getUserName() + "!");
3636
break;
3737
}
38-
if (Engine.questionCounter == Engine.MAX_QUESTIONS) {
39-
System.out.println("Congratulations, " + Engine.userName + "!");
38+
if (Engine.getQuestionCounter() == Engine.getMaxQuestions()) {
39+
System.out.println("Congratulations, " + Engine.getUserName() + "!");
4040
}
4141

4242
}

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import java.util.Scanner;
55

66
public class Engine {
7-
public static String userName = "";
8-
public static int questionCounter = 0;
9-
public static final int MAX_QUESTIONS = 3;
7+
private static String userName = "";
8+
private static int questionCounter = 0;
9+
private static final int MAX_QUESTIONS = 3;
1010

1111
public static void userGreetings() {
1212
Scanner sc = new Scanner(System.in);
@@ -46,4 +46,20 @@ public static int gcdGenerate(int a, int b) {
4646
}
4747
return a;
4848
}
49+
public static String getUserName(){
50+
return userName;
51+
}
52+
public static int getMaxQuestions() {
53+
return MAX_QUESTIONS;
54+
}
55+
public static int getQuestionCounter() {
56+
return questionCounter;
57+
}
58+
public static void setQuestionCounter(int newValue) {
59+
questionCounter = newValue;
60+
}
61+
public static void incrementQuestionsCounter() {
62+
questionCounter++;
63+
}
64+
4965
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ public static void gameLogic() {
88
Scanner sc = new Scanner(System.in);
99
Engine.userGreetings();
1010
System.out.println("Answer 'yes' if the number is even, otherwise answer 'no'.");
11-
while (Engine.questionCounter != Engine.MAX_QUESTIONS) {
11+
while (Engine.getQuestionCounter() != Engine.getMaxQuestions()) {
1212
Random rand = new Random();
1313
int randNum = rand.nextInt(rndMax);
1414
System.out.println("Question: " + randNum);
1515
System.out.print("Your answer: ");
1616
String answer = sc.next();
1717
if (randNum % 2 == 0 && answer.equals("yes")) {
18-
System.out.println("Correct! " + Engine.userName + "\n");
19-
Engine.questionCounter++;
18+
System.out.println("Correct! " + Engine.getUserName() + "\n");
19+
Engine.incrementQuestionsCounter();
2020
} else if (randNum % 2 != 0 && answer.equals("no")) {
2121
System.out.println("Correct!\n");
22-
Engine.questionCounter++;
22+
Engine.incrementQuestionsCounter();
2323
} else {
24-
System.out.println("Let's try again, " + Engine.userName + "!");
24+
System.out.println("Let's try again, " + Engine.getUserName() + "!");
2525
break;
2626
}
27-
if (Engine.questionCounter == Engine.MAX_QUESTIONS) {
28-
System.out.println("Congratulations, " + Engine.userName + "!");
27+
if (Engine.getQuestionCounter() == Engine.getMaxQuestions()) {
28+
System.out.println("Congratulations, " + Engine.getUserName() + "!");
2929
}
3030
}
3131
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void gameLogic() {
1010
System.out.println("Find the greatest common divisor of given numbers.");
1111
Scanner sc = new Scanner(System.in);
1212
int result;
13-
while (Engine.questionCounter != Engine.MAX_QUESTIONS) {
13+
while (Engine.getQuestionCounter() != Engine.getMaxQuestions()) {
1414
Random randNum = new Random();
1515
int num1 = randNum.nextInt(maxValue);
1616
int num2 = randNum.nextInt(maxValue);
@@ -19,16 +19,16 @@ public static void gameLogic() {
1919
result = Engine.gcdGenerate(num1, num2);
2020
if (answer == result) {
2121
System.out.println("Correct!\n");
22-
Engine.questionCounter++;
22+
Engine.incrementQuestionsCounter();
2323
} else {
2424
System.out.println("Your answer: " + answer);
2525
System.out.println("'" + answer + "'" + "is wrong answer ;(. "
2626
+ "Correct answer was" + "'" + result + "'");
27-
System.out.println("Let's try again, " + Engine.userName + "!");
27+
System.out.println("Let's try again, " + Engine.getUserName() + "!");
2828
break;
2929
}
30-
if (Engine.questionCounter == Engine.MAX_QUESTIONS) {
31-
System.out.println("Congratulations, " + Engine.userName + "!");
30+
if (Engine.getQuestionCounter() == Engine.getMaxQuestions()) {
31+
System.out.println("Congratulations, " + Engine.getUserName() + "!");
3232
}
3333
}
3434
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void gameLogic() {
1010
Random randNum = new Random();
1111
Engine.userGreetings();
1212
System.out.println("Answer 'yes' if given number is prime. Otherwise answer 'no'.");
13-
while (Engine.questionCounter != Engine.MAX_QUESTIONS) {
13+
while (Engine.getQuestionCounter() != Engine.getMaxQuestions()) {
1414
int num = randNum.nextInt(2, rndMax);
1515
boolean isPrime = true;
1616
System.out.println("Question: " + num);
@@ -24,16 +24,16 @@ public static void gameLogic() {
2424
String answer = sc.next();
2525
if (answer.equals("yes") && isPrime) {
2626
System.out.println("Correct!");
27-
Engine.questionCounter++;
27+
Engine.incrementQuestionsCounter();
2828
} else if (answer.equals("no") && !isPrime) {
2929
System.out.println("Correct!");
30-
Engine.questionCounter++;
30+
Engine.incrementQuestionsCounter();
3131
} else {
32-
System.out.println("Let's try again, " + Engine.userName + "!");
32+
System.out.println("Let's try again, " + Engine.getUserName() + "!");
3333
break;
3434
}
35-
if (Engine.questionCounter == Engine.MAX_QUESTIONS) {
36-
System.out.println("Congratulations, " + Engine.userName + "!");
35+
if (Engine.getQuestionCounter() == Engine.getMaxQuestions()) {
36+
System.out.println("Congratulations, " + Engine.getUserName() + "!");
3737
}
3838
}
3939
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void gameLogic() {
1515

1616
Engine.userGreetings();
1717
System.out.println("What number is missing in the progression?");
18-
while (Engine.questionCounter != Engine.MAX_QUESTIONS) {
18+
while (Engine.getQuestionCounter() != Engine.getMaxQuestions()) {
1919
int progressionStep = randNum.nextInt(1, stepMax);
2020
int randHideElement = randNum.nextInt(0, hideElementMax);
2121
int firstNum = randNum.nextInt(1, firstNumMax);
@@ -37,16 +37,16 @@ public static void gameLogic() {
3737

3838
if (answer == hideElement) {
3939
System.out.println("Correct!\n");
40-
Engine.questionCounter++;
40+
Engine.incrementQuestionsCounter();
4141
} else {
4242
System.out.println("Your answer: " + answer);
4343
System.out.println("'" + answer + "'" + "is wrong answer ;(. "
4444
+ "Correct answer was" + "'" + hideElement + "'");
45-
System.out.println("Let's try again, " + Engine.userName + "!");
45+
System.out.println("Let's try again, " + Engine.getUserName() + "!");
4646
break;
4747
}
48-
if (Engine.questionCounter == Engine.MAX_QUESTIONS) {
49-
System.out.println("Congratulations, " + Engine.userName + "!");
48+
if (Engine.getQuestionCounter() == Engine.getMaxQuestions()) {
49+
System.out.println("Congratulations, " + Engine.getUserName() + "!");
5050
}
5151
}
5252

0 commit comments

Comments
 (0)