Skip to content

Commit

Permalink
Try do delete magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman3455 committed Jul 28, 2024
1 parent 5ff93bc commit 34d98a2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/hexlet/code/games/Calc.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ public static void isGameLoop() {

int maxWin = 3;
int countCorrectAnswers = 0;
int boundNum = 100;
int compOperationNum = 3;
while (countCorrectAnswers < maxWin) {
int computingOperation = Randomizer.getRandomIntNum(3);
int randNum1 = Randomizer.getRandomIntNum(100);
int randNum2 = Randomizer.getRandomIntNum(100);
int computingOperation = Randomizer.getRandomIntNum(compOperationNum);
int randNum1 = Randomizer.getRandomIntNum(boundNum);
int randNum2 = Randomizer.getRandomIntNum(boundNum);

String question;
int result;
Expand Down Expand Up @@ -48,7 +50,7 @@ public static void isGameLoop() {
countCorrectAnswers++;
}

if (countCorrectAnswers == 3) {
if (countCorrectAnswers == maxWin) {
System.out.println("Congratulations, " + userName + "!");
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/hexlet/code/games/Even.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public static void isGameLoop() {

int maxWin = 3;
int countCorrectAnswers = 0;
int boundNum = 100;
while (countCorrectAnswers < maxWin) {
int num = Randomizer.getRandomIntNum(100);
int num = Randomizer.getRandomIntNum(boundNum);
boolean numBoolean = (num % 2 == 0);
System.out.println("Question: " + num);
System.out.print("Your answer: ");
Expand Down Expand Up @@ -47,7 +48,7 @@ public static void isGameLoop() {
countCorrectAnswers++;
}

if (countCorrectAnswers == 3) {
if (countCorrectAnswers == maxWin) {
System.out.println("Congratulations, " + userName + "!");
}
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/hexlet/code/games/GCD.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public static void isGameLoop() {

int maxWin = 3;
int countCorrectAnswers = 0;
int boundNum = 100;
while (countCorrectAnswers < maxWin) {
int randNum1 = Randomizer.getRandomIntNum(100);
int randNum2 = Randomizer.getRandomIntNum(100);
int randNum1 = Randomizer.getRandomIntNum(boundNum);
int randNum2 = Randomizer.getRandomIntNum(boundNum);
System.out.println("Question: " + randNum1 + " " + randNum2);
System.out.print("Your answer: ");
int userAnswer = ScannerUtil.nextInt();
Expand All @@ -29,7 +30,7 @@ public static void isGameLoop() {
countCorrectAnswers++;
}

if (countCorrectAnswers == 3) {
if (countCorrectAnswers == maxWin) {
System.out.println("Congratulations, " + userName + "!");
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/hexlet/code/games/Prime.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public static void isGameLoop() {

int maxWin = 3;
int countCorrectAnswers = 0;
int boundNum = 200;
while (countCorrectAnswers < maxWin) {
int num = Randomizer.getRandomIntNum(200);
int num = Randomizer.getRandomIntNum(boundNum);
boolean numBoolean = isPrimeCheck(num);
System.out.println("Question: " + num);
System.out.print("Your answer: ");
Expand Down Expand Up @@ -45,7 +46,7 @@ public static void isGameLoop() {
System.out.println("Correct!");
countCorrectAnswers++;
}
if (countCorrectAnswers == 3) {
if (countCorrectAnswers == maxWin) {
System.out.println("Congratulations, " + userName + "!");
}
}
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/hexlet/code/games/Progression.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ public static void isGameLoop() {

int maxWin = 3;
int countCorrectAnswers = 0;
int minProgrLength = 5;
int maxProgrLength = 11;
int minProgrStep = 2;
int maxProgrStep = 6;
int minFirstVal = -50;
int maxFirstVal = 51;
while (countCorrectAnswers < maxWin) {
int progressionLength = Randomizer.getRandomIntNum(5, 11);
int progressionLength = Randomizer.getRandomIntNum(minProgrLength, maxProgrLength);
int[] progressionArr = new int[progressionLength];
int progressionStep = Randomizer.getRandomIntNum(2, 6);
int progressionStep = Randomizer.getRandomIntNum(minProgrStep, maxProgrStep);
int randIndex = Randomizer.getRandomIntNum(progressionArr.length);
progressionArr[0] = Randomizer.getRandomIntNum(-50, 51);
progressionArr[0] = Randomizer.getRandomIntNum(minFirstVal, maxFirstVal);
for (int i = 1; i < progressionLength; i++) {
progressionArr[i] = progressionArr[i - 1] + progressionStep;
}
Expand All @@ -42,7 +48,7 @@ public static void isGameLoop() {
countCorrectAnswers++;
}

if (countCorrectAnswers == 3) {
if (countCorrectAnswers == maxWin) {
System.out.println("Congratulations, " + userName + "!");
}
}
Expand Down

0 comments on commit 34d98a2

Please sign in to comment.