Skip to content

Commit 12063df

Browse files
committed
Added GCDGame class
1 parent e3d06f8 commit 12063df

File tree

10 files changed

+239
-28
lines changed

10 files changed

+239
-28
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@
99
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
1010
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
1111
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
12+
13+
https://asciinema.org/a/Iaff6ukLhja6iQoGAjxWDoeOu
14+
https://asciinema.org/a/88N93aimt7NfYdxmFRtSMhTnb
15+
https://asciinema.org/a/1FHH1S1pSiaUlHgbpE2ZT1Dhb
16+

app/GCD.cast

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{"version": 2, "width": 134, "height": 24, "timestamp": 1759586857, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
2+
[0.022135, "o", "\u001b[?2004h\u001b]0;aseccxz@aseccxz-Lenovo-Legion-5-15ARH05H: ~/firstProject/java-project-61/app\u0007\u001b[01;32maseccxz@aseccxz-Lenovo-Legion-5-15ARH05H\u001b[00m:\u001b[01;34m~/firstProject/java-project-61/app\u001b[00m$ "]
3+
[1.170219, "o", "m"]
4+
[1.341632, "o", "a"]
5+
[1.465089, "o", "k"]
6+
[1.618348, "o", "e"]
7+
[2.005345, "o", " "]
8+
[2.190232, "o", "run-dist "]
9+
[2.854423, "o", "\r\n\u001b[?2004l\r"]
10+
[2.85953, "o", "./build/install/app/bin/app\r\n"]
11+
[2.903932, "o", "Please enter the game number and press Enter.\r\n1 - Greet\r\n2 - Even\r\n3 - Calc\r\n4 - GCD\r\n0 - Exit\r\n"]
12+
[4.394435, "o", "4"]
13+
[4.578093, "o", "\r\n"]
14+
[4.593554, "o", "Your choice: 4\r\n"]
15+
[4.594455, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
16+
[6.424849, "o", "A"]
17+
[6.698049, "o", "l"]
18+
[6.825408, "o", "e"]
19+
[7.114623, "o", "x"]
20+
[7.30569, "o", "\r\n"]
21+
[7.316952, "o", "Hello, Alex!\r\n"]
22+
[7.333171, "o", "Question: 69 34\r\n"]
23+
[9.622454, "o", "1"]
24+
[9.765725, "o", "\r\n"]
25+
[9.766112, "o", "Correct!\r\n"]
26+
[9.766418, "o", "Find the greatest common divisor of given numbers.\r\nQuestion: 81 91\r\n"]
27+
[11.586498, "o", "1"]
28+
[11.709865, "o", "\r\n"]
29+
[11.710219, "o", "Correct!\r\n"]
30+
[11.710466, "o", "Find the greatest common divisor of given numbers.\r\n"]
31+
[11.710625, "o", "Question: 17 23\r\n"]
32+
[13.13398, "o", "1"]
33+
[13.241329, "o", "\r\n"]
34+
[13.241699, "o", "Correct!\r\n"]
35+
[13.242409, "o", "Congratulations, Alex!\r\n"]
36+
[13.257532, "o", "\u001b[?2004h\u001b]0;aseccxz@aseccxz-Lenovo-Legion-5-15ARH05H: ~/firstProject/java-project-61/app\u0007\u001b[01;32maseccxz@aseccxz-Lenovo-Legion-5-15ARH05H\u001b[00m:\u001b[01;34m~/firstProject/java-project-61/app\u001b[00m$ "]
37+
[16.181826, "o", "make run-dist "]
38+
[16.858573, "o", "\r\n\u001b[?2004l\r"]
39+
[16.862666, "o", "./build/install/app/bin/app\r\n"]
40+
[16.908927, "o", "Please enter the game number and press Enter.\r\n1 - Greet\r\n2 - Even\r\n3 - Calc\r\n4 - GCD\r\n0 - Exit\r\n"]
41+
[18.15474, "o", "4"]
42+
[18.330284, "o", "\r\n"]
43+
[18.34843, "o", "Your choice: 4\r\n"]
44+
[18.349843, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
45+
[20.070446, "o", "A"]
46+
[20.382413, "o", "l"]
47+
[20.518574, "o", "e"]
48+
[20.773722, "o", "x"]
49+
[20.917693, "o", "\r\n"]
50+
[20.930604, "o", "Hello, Alex!\r\n"]
51+
[20.941841, "o", "Question: 32 95\r\n"]
52+
[23.329631, "o", "1"]
53+
[23.425715, "o", "\r\n"]
54+
[23.426139, "o", "Correct!\r\n"]
55+
[23.42633, "o", "Find the greatest common divisor of given numbers.\r\n"]
56+
[23.426471, "o", "Question: 79 69\r\n"]
57+
[24.537697, "o", "1"]
58+
[24.633232, "o", "\r\n"]
59+
[24.633652, "o", "Correct!\r\n"]
60+
[24.633755, "o", "Find the greatest common divisor of given numbers.\r\n"]
61+
[24.633869, "o", "Question: 65 15\r\n"]
62+
[28.162128, "o", "2"]
63+
[28.321665, "o", "3"]
64+
[28.998132, "o", "\r\n"]
65+
[29.013065, "o", "'23' is wrong answer ;(. Correct answer was '5'.\r\n"]
66+
[29.013369, "o", "Let's try again, Alex!\r\n"]
67+
[29.03548, "o", "\u001b[?2004h\u001b]0;aseccxz@aseccxz-Lenovo-Legion-5-15ARH05H: ~/firstProject/java-project-61/app\u0007\u001b[01;32maseccxz@aseccxz-Lenovo-Legion-5-15ARH05H\u001b[00m:\u001b[01;34m~/firstProject/java-project-61/app\u001b[00m$ "]
68+
[32.954624, "o", "\u001b[?2004l\r\r\nexit\r\n"]

app/calc.cast

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{"version": 2, "width": 134, "height": 24, "timestamp": 1759584699, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
2+
[0.029246, "o", "\u001b[?2004h\u001b]0;aseccxz@aseccxz-Lenovo-Legion-5-15ARH05H: ~/firstProject/java-project-61/app\u0007\u001b[01;32maseccxz@aseccxz-Lenovo-Legion-5-15ARH05H\u001b[00m:\u001b[01;34m~/firstProject/java-project-61/app\u001b[00m$ "]
3+
[2.388723, "o", "make run-dist "]
4+
[3.370388, "o", "\r\n\u001b[?2004l\r"]
5+
[3.374764, "o", "./build/install/app/bin/app\r\n"]
6+
[3.421155, "o", "Please enter the game number and press Enter.\r\n1 - Greet\r\n2 - Even\r\n3 - Calc\r\n0 - Exit\r\n"]
7+
[4.996078, "o", "3"]
8+
[6.107198, "o", "\r\n"]
9+
[6.119065, "o", "Your choice: 3\r\n"]
10+
[6.121042, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
11+
[8.984126, "o", "A"]
12+
[9.451854, "o", "l"]
13+
[9.575533, "o", "e"]
14+
[9.863975, "o", "x"]
15+
[10.023323, "o", "\r\n"]
16+
[10.037274, "o", "Hello, Alex!\r\n"]
17+
[10.039026, "o", "What is the result of the expression?\r\n"]
18+
[10.060161, "o", "Question: 1 + 5\r\n"]
19+
[11.833771, "o", "6"]
20+
[12.096243, "o", "\r\n"]
21+
[12.097065, "o", "Correct!\r\n"]
22+
[12.09742, "o", "Question: 7 * 9\r\n"]
23+
[18.740031, "o", "6"]
24+
[19.35897, "o", "3"]
25+
[20.09225, "o", "\r\n"]
26+
[20.092697, "o", "Correct!\r\n"]
27+
[20.092953, "o", "Question: 7 - 7\r\n"]
28+
[21.689149, "o", "0"]
29+
[22.306347, "o", "\r\n"]
30+
[22.306751, "o", "Correct!\r\n"]
31+
[22.307402, "o", "Congratulations, Alex!\r\n"]
32+
[22.318486, "o", "\u001b[?2004h\u001b]0;aseccxz@aseccxz-Lenovo-Legion-5-15ARH05H: ~/firstProject/java-project-61/app\u0007\u001b[01;32maseccxz@aseccxz-Lenovo-Legion-5-15ARH05H\u001b[00m:\u001b[01;34m~/firstProject/java-project-61/app\u001b[00m$ "]
33+
[23.752355, "o", "make run-dist "]
34+
[24.566735, "o", "\r\n\u001b[?2004l\r"]
35+
[24.570611, "o", "./build/install/app/bin/app\r\n"]
36+
[24.619624, "o", "Please enter the game number and press Enter.\r\n1 - Greet\r\n2 - Even\r\n3 - Calc\r\n0 - Exit\r\n"]
37+
[25.912107, "o", "3"]
38+
[26.055498, "o", "\r\n"]
39+
[26.061494, "o", "Your choice: 3\r\n"]
40+
[26.06203, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
41+
[27.600267, "o", "A"]
42+
[27.979898, "o", "l"]
43+
[28.079901, "o", "e"]
44+
[28.336033, "o", "x"]
45+
[28.500049, "o", "\r\n"]
46+
[28.513806, "o", "Hello, Alex!\r\n"]
47+
[28.516168, "o", "What is the result of the expression?\r\n"]
48+
[28.524472, "o", "Question: 1 - 10\r\n"]
49+
[31.460774, "o", "1"]
50+
[31.619665, "o", "0"]
51+
[31.755713, "o", "0"]
52+
[32.391504, "o", "\r\n"]
53+
[32.402232, "o", "'100' is wrong answer ;(. Correct answer was '-9'.\r\n"]
54+
[32.40343, "o", "Let's try again, Alex!\r\n"]
55+
[32.421549, "o", "\u001b[?2004h"]
56+
[32.421744, "o", "\u001b]0;aseccxz@aseccxz-Lenovo-Legion-5-15ARH05H: ~/firstProject/java-project-61/app\u0007\u001b[01;32maseccxz@aseccxz-Lenovo-Legion-5-15ARH05H\u001b[00m:\u001b[01;34m~/firstProject/java-project-61/app\u001b[00m$ "]
57+
[36.6245, "o", "\u001b[?2004l\r\r\nexit\r\n"]

app/demo.cast

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{"version": 2, "width": 134, "height": 24, "timestamp": 1759584341, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
2+
[0.023496, "o", "\u001b[?2004h\u001b]0;aseccxz@aseccxz-Lenovo-Legion-5-15ARH05H: ~/firstProject/java-project-61/app\u0007\u001b[01;32maseccxz@aseccxz-Lenovo-Legion-5-15ARH05H\u001b[00m:\u001b[01;34m~/firstProject/java-project-61/app\u001b[00m$ "]
3+
[8.235886, "o", "./gradlew checkstyleMain"]
4+
[8.755955, "o", "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\u001b[9Ptasks"]
5+
[9.259297, "o", "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\u001b[1Pmake run-dist "]
6+
[10.186478, "o", "\r\n\u001b[?2004l\r"]
7+
[10.190608, "o", "./build/install/app/bin/app\r\n"]
8+
[10.235904, "o", "Please enter the game number and press Enter.\r\n1 - Greet\r\n2 - Even\r\n3 - Calc\r\n0 - Exit\r\n"]
9+
[15.427714, "o", "2"]
10+
[15.671614, "o", "\r\n"]
11+
[15.680986, "o", "Your choice: 2\r\n"]
12+
[15.681388, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
13+
[17.936006, "o", "A"]
14+
[18.27602, "o", "l"]
15+
[18.391491, "o", "e"]
16+
[18.672, "o", "x"]
17+
[19.374717, "o", "\r\n"]
18+
[19.390665, "o", "Hello, Alex!\r\n"]
19+
[19.391817, "o", "Answer 'yes' if the number is even, otherwise answer 'no'.\r\n"]
20+
[19.397377, "o", "Question: 82\r\n"]
21+
[22.290499, "o", "y"]
22+
[22.405658, "o", "e"]
23+
[22.739004, "o", "s"]
24+
[23.591844, "o", "\r\n"]
25+
[23.592599, "o", "Correct!\r\n"]
26+
[23.592724, "o", "Question: 22\r\n"]
27+
[25.10367, "o", "y"]
28+
[25.250781, "o", "e"]
29+
[25.515736, "o", "s"]
30+
[25.738754, "o", "\r\n"]
31+
[25.739137, "o", "Correct!\r\n"]
32+
[25.739299, "o", "Question: 68\r\n"]
33+
[27.11157, "o", "y"]
34+
[27.279569, "o", "e"]
35+
[27.551861, "o", "s"]
36+
[28.782277, "o", "\r\n"]
37+
[28.782718, "o", "Correct!\r\n"]
38+
[28.783551, "o", "Congratulations, Alex!\r\n"]
39+
[28.802084, "o", "\u001b[?2004h\u001b]0;aseccxz@aseccxz-Lenovo-Legion-5-15ARH05H: ~/firstProject/java-project-61/app\u0007\u001b[01;32maseccxz@aseccxz-Lenovo-Legion-5-15ARH05H\u001b[00m:\u001b[01;34m~/firstProject/java-project-61/app\u001b[00m$ "]
40+
[32.143497, "o", "make run-dist "]
41+
[32.784037, "o", "\r\n\u001b[?2004l\r"]
42+
[32.787604, "o", "./build/install/app/bin/app\r\n"]
43+
[32.830529, "o", "Please enter the game number and press Enter.\r\n1 - Greet\r\n2 - Even\r\n3 - Calc\r\n0 - Exit\r\n"]
44+
[35.527356, "o", "2"]
45+
[35.83127, "o", "\r\n"]
46+
[35.844371, "o", "Your choice: 2\r\n"]
47+
[35.844791, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
48+
[38.321716, "o", "A"]
49+
[38.649898, "o", "l"]
50+
[38.761211, "o", "e"]
51+
[39.037808, "o", "x"]
52+
[39.209594, "o", "\r\n"]
53+
[39.223196, "o", "Hello, Alex!\r\n"]
54+
[39.224351, "o", "Answer 'yes' if the number is even, otherwise answer 'no'.\r\n"]
55+
[39.225483, "o", "Question: 63\r\n"]
56+
[41.197935, "o", "y"]
57+
[41.330383, "o", "e"]
58+
[41.642546, "o", "s"]
59+
[43.120409, "o", "\r\n"]
60+
[43.135369, "o", "'yes' is wrong answer ;(. Correct answer was 'no'.\r\nLet's try again, Alex!\r\n"]
61+
[43.153773, "o", "\u001b[?2004h\u001b]0;aseccxz@aseccxz-Lenovo-Legion-5-15ARH05H: ~/firstProject/java-project-61/app\u0007\u001b[01;32maseccxz@aseccxz-Lenovo-Legion-5-15ARH05H\u001b[00m:\u001b[01;34m~/firstProject/java-project-61/app\u001b[00m$ "]
62+
[45.698853, "o", "\u001b[?2004l\r\r\nexit\r\n"]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static void main(String[] args) {
99
1 - Greet
1010
2 - Even
1111
3 - Calc
12+
4 - GCD
1213
0 - Exit""");
1314
int gameChoice;
1415
Scanner input = new Scanner(System.in);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Cli {
77

88
public static void greeting() {
99
System.out.println("Welcome to the Brain Games!");
10-
if(name == null){
10+
if (name == null) {
1111
System.out.print("May I have your name? ");
1212
Scanner input = new Scanner(System.in);
1313
name = input.nextLine();

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,30 @@
22

33
import hexlet.code.games.CalcGame;
44
import hexlet.code.games.EvenGame;
5+
import hexlet.code.games.GCDGame;
56

67
import java.util.Scanner;
78

89
public class Engine {
910
public static void gameRun(int gameNum) {
1011
Cli.greeting();
11-
boolean showGameRules = true;
1212
int gameCount = 0;
1313
String solution = "";
1414
String playerAnswer;
1515
Scanner input = new Scanner(System.in);
1616
while (gameCount < 3) {
1717
switch (gameNum) {
1818
case 2:
19-
if (showGameRules) {
20-
EvenGame.gameRules();
21-
showGameRules = false;
22-
}
19+
EvenGame.showGameRules(gameCount);
2320
solution = EvenGame.getSolution();
2421
break;
2522
case 3:
26-
if (showGameRules) {
27-
CalcGame.gameRules();
28-
showGameRules = false;
29-
}
23+
CalcGame.showGameRules(gameCount);
3024
solution = CalcGame.getSolution();
3125
break;
26+
case 4:
27+
GCDGame.showGameRules(gameCount);
28+
solution = GCDGame.getSolution();
3229
}
3330
playerAnswer = input.nextLine();
3431
if (solution.equals(playerAnswer)) {
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
package hexlet.code.games;
22

33
public class CalcGame {
4-
public static void gameRules() {
5-
System.out.println("What is the result of the expression?");
4+
public static void showGameRules(int gameCount) {
5+
if (gameCount != 0) {
6+
System.out.println("What is the result of the expression?");
7+
}
68
}
79
public static String getSolution() {
810
int firstNumber = (int) (Math.random() * 20.0);
911
int secondNumber = (int) (Math.random() * 20.0);
1012
int operatorIndex = (int) (Math.random() * 3.0);
11-
char[] operator = {'+', '-','*'};
13+
char[] operator = {'+', '-', '*'};
1214
int solution = 0;
1315
System.out.println("Question: " + firstNumber + " " + operator[operatorIndex] + " " + secondNumber);
14-
switch (operator[operatorIndex]) {
15-
case '+':
16-
solution = firstNumber + secondNumber;
17-
break;
18-
case '-':
19-
solution = firstNumber - secondNumber;
20-
break;
21-
case '*':
22-
solution = firstNumber * secondNumber;
23-
break;
24-
}
16+
solution = switch (operator[operatorIndex]) {
17+
case '+' -> firstNumber + secondNumber;
18+
case '-' -> firstNumber - secondNumber;
19+
case '*' -> firstNumber * secondNumber;
20+
default -> solution;
21+
};
2522
return Integer.toString(solution);
2623
}
2724
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package hexlet.code.games;
22

33
public class EvenGame {
4-
public static void gameRules() {
5-
System.out.println("Answer 'yes' if the number is even, otherwise answer 'no'.");
4+
public static void showGameRules(int gameCount) {
5+
if (gameCount != 0) {
6+
System.out.println("Answer 'yes' if the number is even, otherwise answer 'no'.");
7+
}
68
}
79
public static String getSolution() {
810
int guessedNumber = (int) (Math.random() * 100.0);
911
System.out.println("Question: " + guessedNumber);
10-
String solution = guessedNumber % 2 == 0 ? "yes" : "no";
11-
return solution;
12+
return guessedNumber % 2 == 0 ? "yes" : "no";
1213
}
1314
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package hexlet.code.games;
2+
3+
public class GCDGame {
4+
public static void showGameRules(int gameCount) {
5+
if (gameCount != 0) {
6+
System.out.println("Find the greatest common divisor of given numbers.");
7+
}
8+
}
9+
public static String getSolution() {
10+
int firstNumber = (int) (Math.random() * 100.0);
11+
int secondNumber = (int) (Math.random() * 100.0);
12+
int solution;
13+
System.out.println("Question: " + firstNumber + " " + secondNumber);
14+
while (secondNumber != 0) {
15+
int swapNumber;
16+
swapNumber = firstNumber % secondNumber;
17+
firstNumber = secondNumber;
18+
secondNumber = swapNumber;
19+
}
20+
solution = firstNumber;
21+
return Integer.toString(solution);
22+
}
23+
}

0 commit comments

Comments
 (0)