Skip to content

Commit 39f18a8

Browse files
committed
Edit project after review
1 parent b3bc6bc commit 39f18a8

File tree

11 files changed

+40
-77
lines changed

11 files changed

+40
-77
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ out/
1515
bin/
1616
*.tmp
1717

18-
# OS
19-
.DS_Store
20-
Thumbs.db
21-
2218
# Logs
2319
*.log
2420
logs/

app/.gitignore

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1+
.PHONY: build run run-dist clean test check
2+
3+
build:
4+
./gradlew build
5+
6+
run:
7+
./gradlew run
8+
19
run-dist:
10+
./gradlew installDist
211
./build/install/app/bin/app
12+
13+
clean:
14+
./gradlew clean
15+
16+
check:
17+
./gradlew checkstyleMain

app/build.gradle.kts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
plugins {
2-
id("java")
32
id("application")
43
id("se.patrikerdes.use-latest-versions") version "0.2.19"
54
id("com.github.ben-manes.versions") version "0.53.0"
@@ -33,19 +32,12 @@ repositories {
3332
}
3433

3534
dependencies {
36-
testImplementation(platform("org.junit:junit-bom:6.0.0"))
37-
testImplementation("org.junit.jupiter:junit-jupiter")
38-
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
3935
implementation("org.apache.commons:commons-lang3:3.19.0")
4036
implementation("org.hibernate.orm:hibernate-core:6.6.0.Final")
4137
}
4238

4339
application { mainClass.set("hexlet.code.App") }
4440

45-
tasks.test {
46-
useJUnitPlatform()
47-
jvmArgs("--enable-preview")
48-
}
4941

5042
tasks.withType<JavaCompile> {
5143
options.compilerArgs.add("--enable-preview")
@@ -56,4 +48,4 @@ tasks.withType<JavaExec> {
5648
}
5749
tasks.getByName("run", JavaExec::class) {
5850
standardInput = System.`in`
59-
}
51+
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import hexlet.code.games.Prime;
88
import java.util.Scanner;
99

10-
class App {
10+
public class App {
11+
public static String userChoice;
1112
public static void main(String[] args) {
1213
System.out.println("Please enter the game number and press Enter.");
1314
System.out.println("1 - Greet");
@@ -20,8 +21,9 @@ public static void main(String[] args) {
2021

2122
Scanner scanner = new Scanner(System.in);
2223
System.out.print("Your choice: ");
24+
userChoice = scanner.next();
2325

24-
switch (scanner.next()) {
26+
switch (userChoice) {
2527
case "1":
2628
System.out.println("Welcome to the Brain Games!");
2729
Cli.greetUser();
@@ -45,7 +47,7 @@ public static void main(String[] args) {
4547
System.out.println("Goodbye!");
4648
break;
4749
default:
48-
System.out.println("Invalid choice");
50+
System.out.println("Unknown user choice: " + userChoice);
4951
break;
5052
}
5153

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
public class Engine {
66
public static final int ROUNDS = 3;
77

8-
public static int getRoundsCount() {
9-
return ROUNDS;
10-
}
118

129
public static void run(String description, String[][] data) {
1310
System.out.println("Welcome to the Brain Games!");
14-
String userName = Cli.greetUser();
15-
System.out.println(description);
11+
System.out.print("May I have your name? ");
1612
Scanner scanner = new Scanner(System.in);
13+
String userName = scanner.next();
14+
System.out.println("Hello, " + userName + "!");
15+
System.out.println(description);
1716

1817
for (int i = 0; i < ROUNDS; i++) {
1918
String question = data[i][0];

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package hexlet.code.games;
22

3+
import hexlet.code.App;
34
import hexlet.code.Engine;
45
import java.security.SecureRandom;
56

67
public class Calculator {
78
static final int NUMBERS_COUNT = 100;
89

910
public static int calculate(int operand1, int operand2, char operator) {
11+
1012
switch (operator) {
1113
case '+':
1214
return operand1 + operand2;
@@ -15,17 +17,17 @@ public static int calculate(int operand1, int operand2, char operator) {
1517
case '*':
1618
return operand1 * operand2;
1719
default:
18-
return 0;
20+
throw new RuntimeException("Unknown user choice" + App.userChoice);
1921
}
2022
}
2123

2224
public static void startGame() {
2325
String description = "What is the result of the expression?";
2426
char[] operators = {'+', '-', '*'};
25-
String[][] data = new String[Engine.getRoundsCount()][2];
27+
String[][] data = new String[Engine.ROUNDS][2];
2628
SecureRandom random = new SecureRandom();
2729

28-
for (int i = 0; i < Engine.getRoundsCount(); i++) {
30+
for (int i = 0; i < Engine.ROUNDS; i++) {
2931

3032
int number1 = random.nextInt(NUMBERS_COUNT) + 1;
3133
int number2 = random.nextInt(NUMBERS_COUNT) + 1;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ public class Even {
88

99
public static void startGame() {
1010
String description = "Answer 'yes' if the number is even, otherwise answer 'no'.";
11-
String[][] data = new String[Engine.getRoundsCount()][2];
11+
String[][] data = new String[Engine.ROUNDS][2];
1212
SecureRandom random = new SecureRandom();
1313

1414

15-
for (int i = 0; i < Engine.getRoundsCount(); i++) {
15+
for (int i = 0; i < Engine.ROUNDS; i++) {
1616

1717
int number = random.nextInt(NUMBERS_COUNT) + 1;
1818
String question = String.valueOf(number);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class Gcd {
77
static final int NUMBERS_COUNT = 100;
88

9-
private static int isGCD(int a, int b) {
9+
private static int theGCD(int a, int b) {
1010
while (b != 0) {
1111
int value = b;
1212
b = a % b;
@@ -17,15 +17,15 @@ private static int isGCD(int a, int b) {
1717

1818
public static void startGame() {
1919
String description = "Find the greatest common divisor of given numbers.";
20-
String[][] data = new String[Engine.getRoundsCount()][2];
20+
String[][] data = new String[Engine.ROUNDS][2];
2121
SecureRandom random = new SecureRandom();
2222

23-
for (int i = 0; i < Engine.getRoundsCount(); i++) {
23+
for (int i = 0; i < Engine.ROUNDS; i++) {
2424

2525
int number1 = random.nextInt(NUMBERS_COUNT) + 1;
2626
int number2 = random.nextInt(NUMBERS_COUNT) + 1;
2727
String question = number1 + " " + number2;
28-
String correctAnswer = String.valueOf(isGCD(number1, number2));
28+
String correctAnswer = String.valueOf(theGCD(number1, number2));
2929

3030
data[i][0] = question;
3131
data[i][1] = correctAnswer;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public static boolean isPrime(int number) {
2020

2121
public static void startGame() {
2222
String description = "Answer 'yes' if given number is prime. Otherwise answer 'no'.";
23-
String[][] data = new String[Engine.getRoundsCount()][2];
23+
String[][] data = new String[Engine.ROUNDS][2];
2424
SecureRandom random = new SecureRandom();
2525

26-
for (int i = 0; i < Engine.getRoundsCount(); i++) {
26+
for (int i = 0; i < Engine.ROUNDS; i++) {
2727

2828
int number = random.nextInt(NUMBERS_COUNT) + 1;
2929
String question = String.valueOf(number);

0 commit comments

Comments
 (0)