Skip to content

Commit b038620

Browse files
committed
add Even game; readme changes
1 parent 36f6c6d commit b038620

File tree

4 files changed

+138
-1
lines changed

4 files changed

+138
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=MatveyStarkov_java-project-61&metric=bugs)](https://sonarcloud.io/summary/new_code?id=MatveyStarkov_java-project-61)
77
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=MatveyStarkov_java-project-61&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=MatveyStarkov_java-project-61)
88
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=MatveyStarkov_java-project-61&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=MatveyStarkov_java-project-61)
9+
[![asciicast](https://asciinema.org/a/apqfcqjAqkNPHWOKPaPPBHXE2.svg)](https://asciinema.org/a/apqfcqjAqkNPHWOKPaPPBHXE2)

app/demo.cast

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{"version": 2, "width": 125, "height": 38, "timestamp": 1764150549, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
2+
[0.028019, "o", "\u001b[?2004h\u001b]0;matt@Stark: ~/Documents/PROJECTS/java-project-61/app\u0007\u001b[01;32mmatt@Stark\u001b[00m:\u001b[01;34m~/Documents/PROJECTS/java-project-61/app\u001b[00m$ "]
3+
[5.131079, "o", "m"]
4+
[5.215302, "o", "a"]
5+
[5.391541, "o", "k"]
6+
[5.429056, "o", "e"]
7+
[5.639045, "o", "\u0007"]
8+
[6.781908, "o", " "]
9+
[7.215301, "o", "run-dist "]
10+
[8.108043, "o", "\r\n"]
11+
[8.113844, "o", "\u001b[?2004l\r"]
12+
[8.118189, "o", "./build/install/app/bin/app\r\n"]
13+
[8.222627, "o", "Please enter the game number and press Enter\r\n"]
14+
[8.279324, "o", "1 - Greet\r\n2 - Even\r\n0 - Exit\r\nYour choice: "]
15+
[9.597417, "o", "2"]
16+
[9.879915, "o", "\r\n"]
17+
[9.883705, "o", "Welcome to the Brain Games\r\n"]
18+
[9.885092, "o", "May I have your name?\r\n"]
19+
[11.093787, "o", "m"]
20+
[11.178419, "o", "a"]
21+
[11.302303, "o", "t"]
22+
[11.511962, "o", "t"]
23+
[11.626964, "o", "\r\n"]
24+
[11.657823, "o", "Hello, matt!\r\n"]
25+
[11.658135, "o", "Answer 'yes' if the number is even, otherwise answer 'no'\r\n"]
26+
[11.67469, "o", "Question: 55\r\nAnswer: "]
27+
[14.608048, "o", "n"]
28+
[14.671533, "o", "o"]
29+
[14.965029, "o", "\r\n"]
30+
[14.966026, "o", "Correct!\r\n"]
31+
[14.966293, "o", "Question: 12\r\n"]
32+
[14.966545, "o", "Answer: "]
33+
[16.287382, "o", "y"]
34+
[16.363889, "o", "e"]
35+
[16.472796, "o", "s"]
36+
[16.592509, "o", "\r\n"]
37+
[16.593313, "o", "Correct!\r\n"]
38+
[16.593791, "o", "Question: 70\r\nAnswer: "]
39+
[18.03855, "o", "y"]
40+
[18.10761, "o", "e"]
41+
[18.169166, "o", "s"]
42+
[18.356728, "o", "\r\n"]
43+
[18.357617, "o", "Correct!\r\n"]
44+
[18.358517, "o", "Congratulations, matt!\r\n"]
45+
[18.380773, "o", "\u001b[?2004h\u001b]0;matt@Stark: ~/Documents/PROJECTS/java-project-61/app\u0007\u001b[01;32mmatt@Stark\u001b[00m:\u001b[01;34m~/Documents/PROJECTS/java-project-61/app\u001b[00m$ "]
46+
[21.558257, "o", "make run-dist "]
47+
[21.718075, "o", "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\u001b[9Pclear"]
48+
[22.862111, "o", "\r\n\u001b[?2004l\r"]
49+
[22.863998, "o", "\u001b[H\u001b[2J\u001b[3J"]
50+
[22.864509, "o", "\u001b[?2004h\u001b]0;matt@Stark: ~/Documents/PROJECTS/java-project-61/app\u0007\u001b[01;32mmatt@Stark\u001b[00m:\u001b[01;34m~/Documents/PROJECTS/java-project-61/app\u001b[00m$ "]
51+
[23.345523, "o", "clear"]
52+
[23.718568, "o", "\b\b\b\b\bmake run-dist "]
53+
[24.299697, "o", "\r\n\u001b[?2004l\r"]
54+
[24.306653, "o", "./build/install/app/bin/app\r\n"]
55+
[24.461719, "o", "Please enter the game number and press Enter\r\n"]
56+
[24.548863, "o", "1 - Greet\r\n2 - Even\r\n0 - Exit\r\nYour choice: "]
57+
[25.475285, "o", "2"]
58+
[26.131914, "o", "\r\n"]
59+
[26.135236, "o", "Welcome to the Brain Games\r\n"]
60+
[26.136418, "o", "May I have your name?\r\n"]
61+
[27.48806, "o", "m"]
62+
[27.541735, "o", "a"]
63+
[27.675792, "o", "t"]
64+
[27.858753, "o", "t"]
65+
[27.947906, "o", "\r\n"]
66+
[27.989122, "o", "Hello, matt!\r\nAnswer 'yes' if the number is even, otherwise answer 'no'\r\n"]
67+
[28.008365, "o", "Question: 41\r\nAnswer: "]
68+
[30.017286, "o", "y"]
69+
[30.085988, "o", "e"]
70+
[30.163782, "o", "s"]
71+
[30.449667, "o", "\r\n"]
72+
[30.463639, "o", "yes is wrong answer ;(. Correct answer was no\r\nLet's try again, matt!\r\n"]
73+
[30.486378, "o", "\u001b[?2004h\u001b]0;matt@Stark: ~/Documents/PROJECTS/java-project-61/app\u0007\u001b[01;32mmatt@Stark\u001b[00m:\u001b[01;34m~/Documents/PROJECTS/java-project-61/app\u001b[00m$ "]
74+
[31.97427, "o", "("]
75+
[32.099454, "o", "("]
76+
[33.474555, "o", "\u0007"]
77+
[37.548296, "o", "\b\u001b[K"]
78+
[37.701382, "o", "\b\u001b[K"]
79+
[37.897332, "o", "e"]
80+
[38.034058, "o", "x"]
81+
[38.405138, "o", "i"]
82+
[38.490504, "o", "t"]
83+
[38.715706, "o", "\r\n\u001b[?2004l\r"]
84+
[38.716028, "o", "exit\r\n"]
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
package hexlet.code;
22

3+
import java.util.Scanner;
4+
35
public class App {
46
public static void main(String[] args) {
5-
Cli.greeting();
7+
System.out.println("Please enter the game number and press Enter");
8+
Scanner scanner = new Scanner(System.in);
9+
System.out.println("1 - Greet\n2 - Even\n0 - Exit");
10+
System.out.print("Your choice: ");
11+
String x = scanner.next();
12+
if (x.equals("1")) {
13+
Cli.greeting();
14+
} else if (x.equals("2")) {
15+
Even.evenGame();
16+
}
617
}
718
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package hexlet.code;
2+
3+
import java.util.Random;
4+
import java.util.Scanner;
5+
6+
public class Even {
7+
public static void evenGame() {
8+
System.out.println("Welcome to the Brain Games");
9+
Scanner scanner = new Scanner(System.in);
10+
System.out.println("May I have your name?");
11+
String name = scanner.next();
12+
System.out.println("Hello, " + name + "!");
13+
int questions = 3;
14+
int i = 0;
15+
String correctAnswer;
16+
System.out.println("Answer 'yes' if the number is even, otherwise answer 'no'");
17+
Random random = new Random();
18+
while (i < questions) {
19+
int num = random.nextInt(99) + 1;
20+
System.out.println("Question: " + num);
21+
if (num % 2 == 0) {
22+
correctAnswer = "yes";
23+
} else {
24+
correctAnswer = "no";
25+
}
26+
System.out.print("Answer: ");
27+
String answer = scanner.next();
28+
if (!answer.equals(correctAnswer)) {
29+
System.out.println(answer + " is wrong answer ;(. Correct answer was " + correctAnswer + "\n"
30+
+ "Let's try again, " + name + "!");
31+
break;
32+
} else {
33+
System.out.println("Correct!");
34+
}
35+
i++;
36+
}
37+
if (i == questions) {
38+
System.out.println("Congratulations, " + name + "!");
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)