File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
app/src/main/java/hexlet/code/games Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ package hexlet .code ;
2+
3+ public class Calc {
4+ public static void gameCalc () {
5+ String userName = Engine .greeting ();
6+
7+ }
8+ }
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 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+ }
You can’t perform that action at this time.
0 commit comments