Skip to content

Commit 7ce31df

Browse files
author
Aleksandr Pronichev
committed
add folder for games
1 parent 99d1251 commit 7ce31df

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package hexlet.code;
2+
3+
public class Calc {
4+
public static void gameCalc() {
5+
String userName = Engine.greeting();
6+
7+
}
8+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package hexlet.code;
2+
3+
import java.util.Scanner;
4+
5+
public class Even {
6+
public static void gameEven() {
7+
String userName = Engine.greeting();
8+
System.out.println("Answer 'yes' if the number is even, otherwise answer 'no'.");
9+
10+
Scanner scanner = new Scanner(System.in);
11+
12+
for (int i = 0; i < 3; i++) {
13+
int guessedNumber = (int) (Math.random() * 100);
14+
System.out.println("Question: " + guessedNumber);
15+
System.out.print("Your answer: ");
16+
String answer = scanner.next();
17+
18+
if (!answer.equals("yes") && !answer.equals("no")) {
19+
System.out.println("'" + answer + "'" + "is wrong answer. Answer should be 'yes' or 'no'");
20+
break;
21+
}
22+
23+
if (guessedNumber % 2 == 0) {
24+
if (answer.equals("yes")) {
25+
System.out.println("Correct!");
26+
} else {
27+
System.out.println("'no' is wrong answer ;(. Correct answer was 'yes'.\n"
28+
+ "Let's try again, " + userName + "!");
29+
break;
30+
}
31+
} else {
32+
if (answer.equals("no")) {
33+
System.out.println("Correct!");
34+
} else {
35+
System.out.println("'yes' is wrong answer ;(. Correct answer was 'no'.\n"
36+
+ "Let's try again, " + userName + "!");
37+
break;
38+
}
39+
}
40+
41+
if (i == 2) {
42+
System.out.println("Congratulations, " + userName + "!");
43+
break;
44+
}
45+
}
46+
scanner.close();
47+
}
48+
49+
}

0 commit comments

Comments
 (0)