Skip to content

Commit 2fe0194

Browse files
committed
creating GCD game, small corrections Calculator and Even
1 parent 6c0a45f commit 2fe0194

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=Antojkv_java-project-61&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=Antojkv_java-project-61)
77

88
Аскинемы:
9-
Even: https://asciinema.org/a/C2DaZpopjiwCQOdQGr5ldJEa4
9+
"Even" https://asciinema.org/a/C2DaZpopjiwCQOdQGr5ldJEa4
1010

11-
Calculator: https://asciinema.org/a/QIkWy2KinHzcdj0LULvdMOfM0
11+
"Calculator" https://asciinema.org/a/QIkWy2KinHzcdj0LULvdMOfM0
12+
13+
"GCD" https://asciinema.org/a/anWD6GPnBTcWTBLCfvbMGZeV6

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import hexlet.code.games.Calculator;
44
import hexlet.code.games.Even;
5-
5+
import hexlet.code.games.Gcd;
66
import java.util.Scanner;
77

88
class App {
@@ -11,6 +11,7 @@ public static void main(String[] args) {
1111
System.out.println("1 - Greet");
1212
System.out.println("2 - Even");
1313
System.out.println("3 - Calculator");
14+
System.out.println("4 - GCD");
1415
System.out.println("0 - Exit");
1516

1617
Scanner scanner = new Scanner(System.in);
@@ -27,6 +28,9 @@ public static void main(String[] args) {
2728
case "3":
2829
Calculator.startGame();
2930
break;
31+
case "4":
32+
Gcd.startGame();
33+
break;
3034
case "0":
3135
System.out.println("Goodbye!");
3236
break;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package hexlet.code;
2+
23
import java.util.Scanner;
34

45
public final class Cli {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package hexlet.code.games;
22

33
import hexlet.code.Engine;
4-
54
import java.security.SecureRandom;
65

76
public class Calculator {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package hexlet.code.games;
2-
import hexlet.code.Engine;
32

3+
import hexlet.code.Engine;
44
import java.security.SecureRandom;
55

66
public class Even {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package hexlet.code.games;
2+
3+
import hexlet.code.Engine;
4+
import java.security.SecureRandom;
5+
6+
public class Gcd {
7+
private static final String DESCRIPTION = "Find the greatest common divisor of given numbers.";
8+
9+
private static int isGCD(int a, int b) {
10+
while (b != 0) {
11+
int value = b;
12+
b = a % b;
13+
a = value;
14+
}
15+
return a;
16+
}
17+
18+
public static void startGame() {
19+
String[][] data = new String[Engine.getRoundsCount()][2];
20+
SecureRandom random = new SecureRandom();
21+
22+
for (int i = 0; i < Engine.getRoundsCount(); i++) {
23+
int number1 = random.nextInt(100) + 1;
24+
int number2 = random.nextInt(100) + 1;
25+
String question = number1 + " " + number2;
26+
String correctAnswer = String.valueOf(isGCD(number1, number2));
27+
28+
data[i][0] = question;
29+
data[i][1] = correctAnswer;
30+
}
31+
Engine.run(DESCRIPTION, data);
32+
}
33+
34+
}

0 commit comments

Comments
 (0)