File tree Expand file tree Collapse file tree 5 files changed +60
-7
lines changed
src/main/java/hexlet/code Expand file tree Collapse file tree 5 files changed +60
-7
lines changed Original file line number Diff line number Diff line change 1+ ### Example(Asciinema)
2+ https://asciinema.org/a/FPppNZRyj39zZUm0gBFfnXw3G
3+
14### Hexlet tests and linter status:
25[ ![ 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 )
36
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ INFO.md
1616out /
1717! ** /src /main /** /out /
1818! ** /src /test /** /out /
19+ .idea /
1920
2021# ## Eclipse ###
2122.apt_generated
Original file line number Diff line number Diff line change 11package hexlet .code ;
22
3+ import java .util .Scanner ;
4+
35public class App {
46 public static void main (String [] args ) {
5- System .out .println ("Welcome to the Brain Games!" );
6- Cli .welcomeUser ();
7+ Scanner scanner = new Scanner (System .in );
8+ System .out .println ("Please enter the game number and press Enter.\n 1 - Greet\n 2 - Even\n 0 - Exit" );
9+ System .out .print ("Your choice : " );
10+ String option = scanner .nextLine ();
11+
12+ switch (option ) {
13+ case "1" :
14+ Cli .greet ();
15+ break ;
16+ case "2" :
17+ Even .evenGame ();
18+ break ;
19+
20+ }
21+ scanner .close ();
722 }
8- }
23+
24+ }
Original file line number Diff line number Diff line change 33import java .util .Scanner ;
44
55public class Cli {
6- public static void welcomeUser () {
6+ public static void greet () {
77 Scanner scanner = new Scanner (System .in );
88
9+ System .out .println ("Welcome to the Brain Games!" );
910 System .out .print ("May I have your name? " );
10- String userName = scanner .next ();
11+ String userName = scanner .nextLine ();
1112 System .out .println ("Hello, " + userName + "!" );
12-
13- scanner .close ();
1413 }
1514}
Original file line number Diff line number Diff line change 1+ package hexlet .code ;
2+
3+ import java .util .Scanner ;
4+
5+ public class Even {
6+ public static void evenGame () {
7+ Scanner scanner = new Scanner (System .in );
8+ System .out .println ("Welcome to the Brain Games!" );
9+ System .out .print ("May I have your name? " );
10+ String userName = scanner .nextLine ();
11+ System .out .println ("Hello, " + userName + "!" );
12+ System .out .println ("Answer 'yes' if the number is even, otherwise answer 'no'." );
13+
14+ for (int i = 1 ; i <= 3 ; i ++) {
15+ int random = (int ) (Math .random () * 1000 ) + 1 ; //границы случайных чисел не были обозначены сделал от 1 до 1000. требуется уточнение у аналитика :)
16+ System .out .println ("Question: " + random );
17+ System .out .print ("Your answer: " );
18+ String answer = scanner .nextLine ();
19+
20+ boolean isEven = random % 2 == 0 ;
21+ String rightAnswer = isEven ? "yes" : "no" ;
22+
23+
24+ if (answer .equals (rightAnswer )) {
25+ System .out .println ("Correct!" );
26+ } else {
27+ System .out .println ("'" + answer + "'" + " is wrong answer ;(. Correct answer was " + "'" + rightAnswer + "'.\n Let's try again, " + userName );
28+ return ;
29+ }
30+ }
31+ System .out .println ("Congratulations, " + userName + "!" );
32+
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments