File tree Expand file tree Collapse file tree 5 files changed +86
-12
lines changed
app/src/main/java/hexlet/code Expand file tree Collapse file tree 5 files changed +86
-12
lines changed Original file line number Diff line number Diff line change 1- ### Example(Asciinema )
1+ ### Demo(Even )
22https://asciinema.org/a/FPppNZRyj39zZUm0gBFfnXw3G
33
4+ ### Demo(Calculator)
5+ https://asciinema.org/a/5NUp6quilr3DtKLHDEYSfAcZ2
6+
47### Hexlet tests and linter status:
58[ ![ 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 )
69
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+
36import java .util .Scanner ;
47
58public class App {
69 public static void main (String [] args ) {
710 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" );
11+ System .out .println ("Please enter the game number and press Enter." );
12+ System .out .println ("1 - Greet" );
13+ System .out .println ("2 - Even" );
14+ System .out .println ("3 - Calc" );
15+ System .out .println ("0 - Exit" );
916 System .out .print ("Your choice : " );
1017 String option = scanner .nextLine ();
1118
@@ -14,9 +21,11 @@ public static void main(String[] args) {
1421 Cli .greet ();
1522 break ;
1623 case "2" :
17- Even .evenGame ();
24+ Even .play ();
25+ break ;
26+ case "3" :
27+ Calc .play ();
1828 break ;
19-
2029 }
2130 scanner .close ();
2231 }
Original file line number Diff line number Diff line change 1+ package hexlet .code ;
2+
3+ import java .util .Scanner ;
4+
5+ public class Engine {
6+ public static String description () {
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+
13+ return userName ;
14+ }
15+
16+ public static int rounds = 3 ;
17+ }
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 Calc {
8+ public static void play () {
9+ String userName = Engine .description ();
10+ System .out .println ("What is the result of the expression?" );
11+ Scanner scanner = new Scanner (System .in );
12+
13+ for (int i = 1 ; i <= Engine .rounds ; i ++) {
14+ int firstValue = (int ) (Math .random () * 100 ) + 1 ;
15+ int secondValue = (int ) (Math .random () * 100 ) + 1 ;
16+ char signs [] = {'+' , '-' , '*' };
17+ char randomSign = signs [(int ) (Math .random () * signs .length )];
18+ int rightAnswer = 0 ;
19+
20+ switch (randomSign ) {
21+ case '+' :
22+ rightAnswer = firstValue + secondValue ;
23+ break ;
24+ case '-' :
25+ rightAnswer = firstValue - secondValue ;
26+ break ;
27+ case '*' :
28+ rightAnswer = firstValue * secondValue ;
29+ break ;
30+ }
31+
32+ System .out .println ("Question: " + firstValue + " " + randomSign + " " + secondValue );
33+ System .out .print ("Your answer: " );
34+ int answer = scanner .nextInt ();
35+
36+ if (answer == rightAnswer ) {
37+ System .out .println ("Correct!" );
38+ } else {
39+ System .out .println ("'" + answer + "' is wrong answer ;(. Correct answer was '" + rightAnswer + "'." );
40+ System .out .println ("Let's try again, " + userName + "!" );
41+ return ;
42+ }
43+ }
44+ System .out .println ("Congratulations, " + userName + "!" );
45+ }
46+ }
Original file line number Diff line number Diff line change 1- package hexlet .code ;
1+ package hexlet .code .games ;
2+
3+ import hexlet .code .Engine ;
24
35import java .util .Scanner ;
46
57public 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 + "!" );
8+ public static void play () {
9+ String userName = Engine .description ();
1210 System .out .println ("Answer 'yes' if the number is even, otherwise answer 'no'." );
11+ Scanner scanner = new Scanner (System .in );
1312
14- for (int i = 1 ; i <= 3 ; i ++) {
13+ for (int i = 1 ; i <= Engine . rounds ; i ++) {
1514 int random = (int ) (Math .random () * 1000 ) + 1 ; //границы случайных чисел не были обозначены сделал от 1 до 1000. требуется уточнение у аналитика :)
1615 System .out .println ("Question: " + random );
1716 System .out .print ("Your answer: " );
You can’t perform that action at this time.
0 commit comments