File tree Expand file tree Collapse file tree 3 files changed +52
-4
lines changed
app/src/main/java/hexlet/code Expand file tree Collapse file tree 3 files changed +52
-4
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ https://asciinema.org/a/5TK9BqwuQriLXfKwwefoqJjLP
1010### Demo 5 (Progression)
1111https://asciinema.org/a/lB79E4WkEmp1207S7mYMDvjjQ
1212
13+ ### Demo 6 (Prime)
14+ https://asciinema.org/a/MarrMPMwxoFQsybLk4IbKAvcA
15+
1316
1417### Hexlet tests and linter status:
1518[ ![ Actions Status] ( https://github.com/alexeichuprikov/qa-auto-engineer-java-project-61/actions/workflows/hexlet-check.yml/badge.svg )] ( https://github.com/alexeichuprikov/qa-auto-engineer-java-project-61/actions )
Original file line number Diff line number Diff line change 11package hexlet .code ;
22
3- import hexlet .code .games .Calc ;
4- import hexlet .code .games .Even ;
5- import hexlet .code .games .Gcd ;
6- import hexlet .code .games .Progression ;
3+ import hexlet .code .games .*;
74
85import java .util .Scanner ;
96
@@ -16,6 +13,7 @@ public static void main(String[] args) {
1613 System .out .println ("3 - Calc" );
1714 System .out .println ("4 - GCD" );
1815 System .out .println ("5 - Progression" );
16+ System .out .println ("6 - Prime" );
1917 System .out .println ("0 - Exit" );
2018 System .out .print ("Your choice : " );
2119 String option = scanner .nextLine ();
@@ -36,6 +34,9 @@ public static void main(String[] args) {
3634 case "5" :
3735 Progression .play ();
3836 break ;
37+ case "6" :
38+ Prime .play ();
39+ break ;
3940 }
4041 scanner .close ();
4142 }
Original file line number Diff line number Diff line change 1+ package hexlet .code .games ;
2+
3+ import hexlet .code .Engine ;
4+
5+ import java .util .Scanner ;
6+
7+ public class Prime {
8+ public static void play () {
9+ String userName = Engine .description ();
10+ System .out .println ("Answer 'yes' if given number is prime. Otherwise answer 'no'." );
11+ Scanner scanner = new Scanner (System .in );
12+
13+ for (int i = 1 ; i <= Engine .rounds ; i ++) {
14+ int num = (int ) (Math .random () * 100 ) + 1 ;
15+ String rightAnswer = Prime (num );
16+
17+ System .out .println ("Question: " + num );
18+ System .out .print ("Your answer: " );
19+ String answer = scanner .next ();
20+
21+ if (answer .equals (rightAnswer )) {
22+ System .out .println ("Correct!" );
23+ } else {
24+ System .out .println ("'" + answer + "' is wrong answer ;(. Correct answer was '" + rightAnswer + "'." );
25+ System .out .println ("Let's try again, " + userName + "!" );
26+ return ;
27+ }
28+ }
29+ System .out .println ("Congratulations, " + userName + "!" );
30+ }
31+
32+
33+ public static String Prime (int num ) {
34+ if (num < 2 ) {
35+ return "no" ;
36+ }
37+ for (int i = 2 ; i <= Math .sqrt (num ); i ++) {
38+ if (num % i == 0 ) {
39+ return "no" ;
40+ }
41+ }
42+ return "yes" ;
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments