File tree Expand file tree Collapse file tree 6 files changed +45
-5
lines changed
app/src/main/java/hexlet/code Expand file tree Collapse file tree 6 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 22
33import hexlet .code .games .Calculator ;
44import hexlet .code .games .Even ;
5-
5+ import hexlet . code . games . Gcd ;
66import java .util .Scanner ;
77
88class 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 ;
Original file line number Diff line number Diff line change 11package hexlet .code ;
2+
23import java .util .Scanner ;
34
45public final class Cli {
Original file line number Diff line number Diff line change 11package hexlet .code .games ;
22
33import hexlet .code .Engine ;
4-
54import java .security .SecureRandom ;
65
76public class Calculator {
Original file line number Diff line number Diff line change 11package hexlet .code .games ;
2- import hexlet .code .Engine ;
32
3+ import hexlet .code .Engine ;
44import java .security .SecureRandom ;
55
66public class Even {
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments