Skip to content

Commit 82bb7bc

Browse files
add Even.java, modify App.java, Cli.java, READMI.md, .gitignore
1 parent df4b131 commit 82bb7bc

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
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

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ INFO.md
1616
out/
1717
!**/src/main/**/out/
1818
!**/src/test/**/out/
19+
.idea/
1920

2021
### Eclipse ###
2122
.apt_generated
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
package hexlet.code;
22

3+
import java.util.Scanner;
4+
35
public 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.\n1 - Greet\n2 - Even\n0 - 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+
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import java.util.Scanner;
44

55
public 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
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 + "'.\nLet's try again, " + userName);
28+
return;
29+
}
30+
}
31+
System.out.println("Congratulations, " + userName + "!");
32+
33+
}
34+
}

0 commit comments

Comments
 (0)