Skip to content

Commit

Permalink
Fix magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman3455 committed Jul 28, 2024
1 parent 0f58456 commit f1ad25c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
16 changes: 8 additions & 8 deletions app/src/main/java/hexlet/code/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ public static void selectOption() {
0-Exit
Your choise:\s""");

int selection = ScannerUtil.nextInt();
String selection = ScannerUtil.next();

switch (selection) {
case 1:
case "1":
Cli.greetings();
break;
case 2:
case "2":
Even.isGameLoop();
break;
case 3:
case "3":
Calc.isGameLoop();
break;
case 4:
case "4":
GCD.isGameLoop();
break;
case 5:
case "5":
Progression.isGameLoop();
break;
case 6:
case "6":
Prime.isGameLoop();
break;
case 0:
case "0":
break;
default:
System.out.println("Invalid value, try again");
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 @@ -6,14 +6,15 @@
import hexlet.code.ScannerUtil;

public class Even {
private static final int NUM_BOUND = 100;

public static void isGameLoop() {
String userName = Cli.greetings();
System.out.println("Answer 'yes' if the number is even, otherwise answer 'no'.");

int countCorrectAnswers = 0;
int boundNum = 100;
while (countCorrectAnswers < MainMenu.MAX_WIN) {
int num = Randomizer.getRandomIntNum(boundNum);
int num = Randomizer.getRandomIntNum(NUM_BOUND);
boolean numBoolean = (num % 2 == 0);
System.out.println("Question: " + num);
System.out.print("Your answer: ");
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 @@ -6,15 +6,16 @@
import hexlet.code.ScannerUtil;

public class GCD {
private static final int NUM_BOUND = 100;

public static void isGameLoop() {
String userName = Cli.greetings();
System.out.println("Find the greatest common divisor of given numbers.");

int countCorrectAnswers = 0;
int boundNum = 100;
while (countCorrectAnswers < MainMenu.MAX_WIN) {
int randNum1 = Randomizer.getRandomIntNum(boundNum);
int randNum2 = Randomizer.getRandomIntNum(boundNum);
int randNum1 = Randomizer.getRandomIntNum(NUM_BOUND);
int randNum2 = Randomizer.getRandomIntNum(NUM_BOUND);
System.out.println("Question: " + randNum1 + " " + randNum2);
System.out.print("Your answer: ");
int userAnswer = ScannerUtil.nextInt();
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 @@ -6,14 +6,15 @@
import hexlet.code.ScannerUtil;

public class Prime {
private static final int NUM_BOUND = 200;

public static void isGameLoop() {
String userName = Cli.greetings();
System.out.println("Answer 'yes' if given number is prime. Otherwise answer 'no'.");

int countCorrectAnswers = 0;
int boundNum = 200;
while (countCorrectAnswers < MainMenu.MAX_WIN) {
int num = Randomizer.getRandomIntNum(boundNum);
int num = Randomizer.getRandomIntNum(NUM_BOUND);
boolean numBoolean = isPrimeCheck(num);
System.out.println("Question: " + num);
System.out.print("Your answer: ");
Expand Down
19 changes: 10 additions & 9 deletions app/src/main/java/hexlet/code/games/Progression.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
import hexlet.code.ScannerUtil;

public class Progression {
private static final int MIN_FIRST_VAL = -50;
private static final int MAX_FIRST_VAL = 51;
private static final int MIN_PROGRESSION_STEP = 2;
private static final int MAX_PROGRESSION_STEP = 6;
private static final int MIN_PROGRESSION_LENGTH = 5;
private static final int MAX_PROGRESSION_LENGTH = 11;

public static void isGameLoop() {
String userName = Cli.greetings();
System.out.println("What number is missing in the progression?");

int countCorrectAnswers = 0;
int minProgrLength = 5;
int maxProgrLength = 11;
int minProgrStep = 2;
int maxProgrStep = 6;
int minFirstVal = -50;
int maxFirstVal = 51;
while (countCorrectAnswers < MainMenu.MAX_WIN) {
int progressionLength = Randomizer.getRandomIntNum(minProgrLength, maxProgrLength);
int progressionLength = Randomizer.getRandomIntNum(MIN_PROGRESSION_LENGTH, MAX_PROGRESSION_LENGTH);
int[] progressionArr = new int[progressionLength];
int progressionStep = Randomizer.getRandomIntNum(minProgrStep, maxProgrStep);
int progressionStep = Randomizer.getRandomIntNum(MIN_PROGRESSION_STEP, MAX_PROGRESSION_STEP);
int randIndex = Randomizer.getRandomIntNum(progressionArr.length);
progressionArr[0] = Randomizer.getRandomIntNum(minFirstVal, maxFirstVal);
progressionArr[0] = Randomizer.getRandomIntNum(MIN_FIRST_VAL, MAX_FIRST_VAL);
for (int i = 1; i < progressionLength; i++) {
progressionArr[i] = progressionArr[i - 1] + progressionStep;
}
Expand Down

0 comments on commit f1ad25c

Please sign in to comment.