Skip to content

Commit b40aea3

Browse files
authored
done among them the works which none other man did
If I had not done among them the works which none other man did, they had not had sin: but now have they both seen and hated both me and my Father. (John 15:24)
1 parent 347e453 commit b40aea3

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
//If I had not done among them the works which none other man did, they had not had sin:
3+
//but now have they both seen and hated both me and my Father. (John 15:24)
4+
5+
package com.javarush.task.task29.task2911;
6+
7+
import java.util.Random;
8+
import java.util.Scanner;
9+
10+
/*
11+
И еще раз рефакторинг
12+
*/
13+
14+
public class Solution {
15+
public static boolean flagWin = false;
16+
17+
public static void main(String[] args) {
18+
new Solution().runGame();
19+
}
20+
21+
private void runGame() {
22+
Random random = new Random();
23+
int secret = random.nextInt(1000);
24+
int tryNumber = -1;
25+
Scanner scanner = new Scanner(System.in);
26+
27+
for (int i = 1; i <= 10; i++) {
28+
System.out.printf("Попытка %d - вводи число: ", i);
29+
tryNumber = scanner.nextInt();
30+
if (tryNumber < secret)
31+
if (i < 10)
32+
System.out.println("Загаданное число больше");
33+
if (tryNumber > secret)
34+
if (i < 10)
35+
System.out.println("Загаданное число меньше");
36+
if (tryNumber == secret){
37+
i = stopGame();
38+
flagWin = true;}
39+
}
40+
if (flagWin)
41+
printCongratulations(tryNumber);
42+
else
43+
printUpset();
44+
}
45+
46+
private void printCongratulations(int number) {
47+
System.out.println();
48+
System.out.println("Ты угадал!");
49+
System.out.println("Загаданное число: " + number);
50+
}
51+
52+
private void printUpset() {
53+
System.out.println();
54+
System.out.println("Ты проиграл!");
55+
}
56+
57+
private int stopGame() {
58+
return 10;
59+
}
60+
}
61+
62+
/*
63+
И еще раз рефакторинг
64+
65+
Задается целое число от 0 до 1000 включительно случайным образом. Пользователь вводит с клавиатуры число.
66+
67+
Программа отвечает, введенное число больше или меньше загаданного. Если за 10 попыток пользователь программы угадывает число - программа выводит:
68+
69+
"Ты угадал!"
70+
71+
"Загаданное число: [number]"
72+
73+
иначе "Ты проиграл!".
74+
75+
Исправь одну ошибку, чтобы код выполнял описанные действия.
76+
77+
78+
79+
80+
81+
Требования:
82+
83+
1. Если за 10 попыток не введено правильного числа - программа должна вывести на экран "Ты проиграл!".
84+
85+
2. Если введено неправильное число, флаг boolean flagWin не должен иметь значение true.
86+
87+
3. Не изменяй сигнатуры методов.
88+
89+
4. Нужно сделать одно изменение в правильном месте программы.
90+
*/

0 commit comments

Comments
 (0)