Skip to content

Commit db1a58f

Browse files
mod magic number, del relation build.gradle.kts, mod Makefile
1 parent 0e6536c commit db1a58f

File tree

9 files changed

+108
-66
lines changed

9 files changed

+108
-66
lines changed

app/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
.PHONY: build install clean run-dist
2+
3+
build:
4+
./gradlew build
5+
6+
install:
7+
./gradlew installDist
8+
9+
clean:
10+
./gradlew clean
11+
112
run-dist:
2-
./build/install/app/bin/app
13+
./build/install/app/bin/app

app/build.gradle.kts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
plugins {
22
id("application")
3-
id("se.patrikerdes.use-latest-versions") version "0.2.19"
4-
id("com.github.ben-manes.versions") version "0.41.0"
53
id("checkstyle")
64
}
75

@@ -21,15 +19,9 @@ repositories {
2119
}
2220

2321
dependencies {
24-
testImplementation(platform("org.junit:junit-bom:5.10.0"))
25-
testImplementation("org.junit.jupiter:junit-jupiter")
2622
implementation("org.apache.commons:commons-lang3:3.14.0")
2723
}
2824

29-
tasks.test {
30-
useJUnitPlatform()
31-
}
32-
3325
tasks.getByName("run", JavaExec::class) {
3426
standardInput = System.`in`
3527
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package hexlet.code;
22

3-
import hexlet.code.games.*;
3+
import hexlet.code.games.Calc;
4+
import hexlet.code.games.Even;
5+
import hexlet.code.games.Gcd;
6+
import hexlet.code.games.Prime;
7+
import hexlet.code.games.Progression;
48

59
import java.util.Scanner;
610

@@ -46,4 +50,4 @@ public static void main(String[] args) {
4650
scanner.close();
4751
}
4852

49-
}
53+
}

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

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,45 @@
22

33
public class Engine {
44

5-
public static int rounds = 3;
6-
public static String questionText = "Question: ";
7-
public static String answerText = "Your answer: ";
8-
public static String correctAnswer = "Correct!";
9-
public static String wrongAnswer = "'%s' is wrong answer ;(. Correct answer was '%s'.";
10-
public static String retry = "Let's try again, %s!";
11-
public static String congratulations = "Congratulations, %s!";
5+
private static final int ROUNDS = 3;
6+
//границы случайных чисел не были обозначены сделал от 1 до 100. требуется уточнение у аналитика
7+
private static final int MAX_NUMBER = 100;
8+
private static final String QUESTION_TEXT = "Question: ";
9+
private static final String ANSWER_TEXT = "Your answer: ";
10+
private static final String CORRECT_ANSWER = "Correct!";
11+
private static final String WRONG_ANSWER = "'%s' is wrong answer ;(. Correct answer was '%s'.";
12+
private static final String RETRY = "Let's try again, %s!";
13+
private static final String CONGRATULATIONS = "Congratulations, %s!";
1214

15+
public static int getRounds() {
16+
return ROUNDS;
17+
}
18+
19+
public static int getMaxNumber() {
20+
return MAX_NUMBER;
21+
}
22+
23+
public static String getQuestionText() {
24+
return QUESTION_TEXT;
25+
}
26+
27+
public static String getAnswerText() {
28+
return ANSWER_TEXT;
29+
}
30+
31+
public static String getCorrectAnswer() {
32+
return CORRECT_ANSWER;
33+
}
34+
35+
public static String getWrongAnswer() {
36+
return WRONG_ANSWER;
37+
}
38+
39+
public static String getRetry() {
40+
return RETRY;
41+
}
42+
43+
public static String getCongratulations() {
44+
return CONGRATULATIONS;
45+
}
1346
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public static void play() {
1111
System.out.println("What is the result of the expression?");
1212
Scanner scanner = new Scanner(System.in);
1313

14-
for (int i = 1; i <= Engine.rounds; i++) {
15-
int firstValue = (int) (Math.random() * 100) + 1;
16-
int secondValue = (int) (Math.random() * 100) + 1;
17-
char signs[] = {'+', '-', '*'};
14+
for (int i = 1; i <= Engine.getRounds(); i++) {
15+
int firstValue = (int) (Math.random() * Engine.getMaxNumber()) + 1;
16+
int secondValue = (int) (Math.random() * Engine.getMaxNumber()) + 1;
17+
char[] signs = {'+', '-', '*'};
1818
char randomSign = signs[(int) (Math.random() * signs.length)];
1919
int rightAnswer = 0;
2020

@@ -33,18 +33,18 @@ public static void play() {
3333
break;
3434
}
3535

36-
System.out.println(Engine.questionText + firstValue + " " + randomSign + " " + secondValue);
37-
System.out.print(Engine.answerText);
36+
System.out.println(Engine.getQuestionText() + firstValue + " " + randomSign + " " + secondValue);
37+
System.out.print(Engine.getAnswerText());
3838
int answer = scanner.nextInt();
3939

4040
if (answer == rightAnswer) {
41-
System.out.println(Engine.correctAnswer);
41+
System.out.println(Engine.getCorrectAnswer());
4242
} else {
43-
System.out.printf(Engine.wrongAnswer, answer, rightAnswer);
44-
System.out.printf(Engine.retry, userName);
43+
System.out.printf(Engine.getWrongAnswer(), answer, rightAnswer);
44+
System.out.printf(Engine.getRetry(), userName);
4545
return;
4646
}
4747
}
48-
System.out.printf(Engine.congratulations, userName);
48+
System.out.printf(Engine.getCongratulations(), userName);
4949
}
5050
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ public static void play() {
1111
System.out.println("Answer 'yes' if the number is even, otherwise answer 'no'.");
1212
Scanner scanner = new Scanner(System.in);
1313

14-
for (int i = 1; i <= Engine.rounds; i++) {
15-
int random = (int) (Math.random() * 1000) + 1; //границы случайных чисел не были обозначены сделал от 1 до 1000. требуется уточнение у аналитика :)
16-
System.out.println(Engine.questionText + random);
17-
System.out.print(Engine.answerText);
14+
for (int i = 1; i <= Engine.getRounds(); i++) {
15+
int random = (int) (Math.random() * Engine.getMaxNumber()) + 1;
16+
System.out.println(Engine.getQuestionText() + random);
17+
System.out.print(Engine.getAnswerText());
1818
String answer = scanner.nextLine();
1919

2020
boolean isEven = random % 2 == 0;
2121
String rightAnswer = isEven ? "yes" : "no";
2222

2323

2424
if (answer.equals(rightAnswer)) {
25-
System.out.println(Engine.correctAnswer);
25+
System.out.println(Engine.getCorrectAnswer());
2626
} else {
27-
System.out.printf(Engine.wrongAnswer, answer, rightAnswer);
28-
System.out.printf(Engine.retry, userName);
27+
System.out.printf(Engine.getWrongAnswer(), answer, rightAnswer);
28+
System.out.printf(Engine.getRetry(), userName);
2929
return;
3030
}
3131
}
32-
System.out.printf(Engine.congratulations, userName);
32+
System.out.printf(Engine.getCongratulations(), userName);
3333

3434
}
3535
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public static void play() {
1111
System.out.println("Find the greatest common divisor of given numbers.");
1212
Scanner scanner = new Scanner(System.in);
1313

14-
for (int i = 1; i <= Engine.rounds; i++) {
15-
int firstValue = (int) (Math.random() * 100) + 1;
16-
int secondValue = (int) (Math.random() * 100) + 1;
14+
for (int i = 1; i <= Engine.getRounds(); i++) {
15+
int firstValue = (int) (Math.random() * Engine.getMaxNumber()) + 1;
16+
int secondValue = (int) (Math.random() * Engine.getMaxNumber()) + 1;
1717
int rightAnswer = 0;
1818

1919
int tempFirstValue = firstValue;
@@ -25,18 +25,18 @@ public static void play() {
2525
tempFirstValue = rightAnswer;
2626
}
2727

28-
System.out.println(Engine.answerText + firstValue + " " + secondValue);
29-
System.out.print(Engine.answerText);
28+
System.out.println(Engine.getQuestionText() + firstValue + " " + secondValue);
29+
System.out.print(Engine.getAnswerText());
3030
int answer = scanner.nextInt();
3131

3232
if (answer == rightAnswer) {
33-
System.out.println(Engine.correctAnswer);
33+
System.out.println(Engine.getCorrectAnswer());
3434
} else {
35-
System.out.printf(Engine.wrongAnswer, answer, rightAnswer);
36-
System.out.printf(Engine.retry, userName);
35+
System.out.printf(Engine.getWrongAnswer(), answer, rightAnswer);
36+
System.out.printf(Engine.getRetry(), userName);
3737
return;
3838
}
3939
}
40-
System.out.printf(Engine.congratulations, userName);
40+
System.out.printf(Engine.getCongratulations(), userName);
4141
}
4242
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ public static void play() {
1111
System.out.println("Answer 'yes' if given number is prime. Otherwise answer 'no'.");
1212
Scanner scanner = new Scanner(System.in);
1313

14-
for (int i = 1; i <= Engine.rounds; i++) {
15-
int num = (int) (Math.random() * 100) + 1;
14+
for (int i = 1; i <= Engine.getRounds(); i++) {
15+
int num = (int) (Math.random() * Engine.getMaxNumber()) + 1;
1616
String rightAnswer = logicPrime(num);
1717

18-
System.out.println(Engine.answerText + num);
19-
System.out.print(Engine.answerText);
18+
System.out.println(Engine.getQuestionText() + num);
19+
System.out.print(Engine.getAnswerText());
2020
String answer = scanner.next();
2121

2222
if (answer.equals(rightAnswer)) {
23-
System.out.println(Engine.correctAnswer);
23+
System.out.println(Engine.getCorrectAnswer());
2424
} else {
25-
System.out.printf(Engine.wrongAnswer, answer, rightAnswer);
26-
System.out.printf(Engine.retry, userName);
25+
System.out.printf(Engine.getWrongAnswer(), answer, rightAnswer);
26+
System.out.printf(Engine.getRetry(), userName);
2727
return;
2828
}
2929
}
30-
System.out.printf(Engine.congratulations, userName);
30+
System.out.printf(Engine.getCongratulations(), userName);
3131
}
3232

3333

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,43 @@
66
import java.util.Scanner;
77

88
public class Progression {
9+
private static final int STEP_COUNT = 10;
10+
private static final int VALUE_COUNT = 10;
11+
912
public static void play() {
1013
String userName = Cli.greet();
1114
System.out.println("What number is missing in the progression?");
1215
Scanner scanner = new Scanner(System.in);
1316

1417

15-
for (int i = 1; i <= Engine.rounds; i++) {
16-
int start = (int) (Math.random() * 20) + 1;
17-
int step = (int) (Math.random() * 10) + 1;
18-
int length = 10;
19-
int[] sequence = addSequence(start, step, length);
18+
for (int i = 1; i <= Engine.getRounds(); i++) {
19+
int start = (int) (Math.random() * Engine.getMaxNumber()) + 1;
20+
int step = (int) (Math.random() * STEP_COUNT) + 1;
21+
int[] sequence = addSequence(start, step, VALUE_COUNT);
2022

21-
int hideIndex = (int) (Math.random() * length);
23+
int hideIndex = (int) (Math.random() * VALUE_COUNT);
2224
int rightAnswer = sequence[hideIndex];
2325

24-
System.out.print(Engine.answerText);
25-
for (int j = 0; j < length; j++) {
26+
System.out.print(Engine.getQuestionText());
27+
for (int j = 0; j < VALUE_COUNT; j++) {
2628
if (j == hideIndex) {
2729
System.out.print(".. ");
2830
} else {
2931
System.out.print(sequence[j] + " ");
3032
}
3133
}
32-
System.out.print(Engine.answerText);
34+
System.out.print(Engine.getAnswerText());
3335
int answer = scanner.nextInt();
3436

3537
if (answer == rightAnswer) {
36-
System.out.println(Engine.correctAnswer);
38+
System.out.println(Engine.getCorrectAnswer());
3739
} else {
38-
System.out.printf(Engine.wrongAnswer, answer, rightAnswer);
39-
System.out.printf(Engine.retry, userName);
40+
System.out.printf(Engine.getWrongAnswer(), answer, rightAnswer);
41+
System.out.printf(Engine.getRetry(), userName);
4042
return;
4143
}
4244
}
43-
System.out.printf(Engine.congratulations, userName);
45+
System.out.printf(Engine.getCongratulations(), userName);
4446
}
4547

4648
public static int[] addSequence(int start, int step, int length) {

0 commit comments

Comments
 (0)