Skip to content

Commit 36fbaae

Browse files
authored
reveal yourself to us
Judas (not Iscariot) said to him, "Lord, what has happened that you are about to reveal yourself to us, and not to the world?" (John 14:22)
1 parent 4112819 commit 36fbaae

1 file changed

Lines changed: 185 additions & 0 deletions

File tree

task14/task1411/Solution.java

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
2+
//Judas (not Iscariot) said to him, "Lord, what has happened that you are about to reveal yourself to us, and not to the world?" (John 14:22)
3+
4+
5+
------------------------------------------------Solution.java------------------------------------------------------------------------
6+
package com.javarush.task.task14.task1411;
7+
8+
import java.io.BufferedReader;
9+
import java.io.InputStreamReader;
10+
11+
/*
12+
User, Loser, Coder and Proger
13+
*/
14+
15+
public class Solution {
16+
public static void main(String[] args) throws Exception {
17+
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
18+
Person person = null;
19+
String key = null;
20+
21+
while(true) {//тут цикл по чтению ключей, пункт 1
22+
String string = reader.readLine();
23+
if (string.equals("user")) {
24+
person = new Person.User(); //создаем объект, пункт 2
25+
doWork(person); //вызываем doWork
26+
continue;
27+
}
28+
else if (string.equals("loser")) {
29+
person = new Person.Loser(); //создаем объект, пункт 2
30+
doWork(person); //вызываем doWork
31+
continue;
32+
}
33+
else if (string.equals("coder")) {
34+
person = new Person.Coder(); //создаем объект, пункт 2
35+
doWork(person); //вызываем doWork
36+
continue;
37+
}
38+
else if (string.equals("proger")) {
39+
person = new Person.Proger(); //создаем объект, пункт 2
40+
doWork(person); //вызываем doWork
41+
continue;
42+
}
43+
else {break;}
44+
}
45+
46+
}
47+
48+
public static void doWork(Person person) {
49+
if (person instanceof Person.User) {((Person.User)person).live();}// пункт 3
50+
else if (person instanceof Person.Loser) {((Person.Loser)person).doNothing();}
51+
else if (person instanceof Person.Coder) {((Person.Coder)person).coding();}
52+
else if (person instanceof Person.Proger) {((Person.Proger)person).enjoy();}
53+
}
54+
}
55+
56+
-------------------------------------------------------------------------------------------------------------------------------------
57+
58+
59+
------------------------------------------------Person.java--------------------------------------------------------------------------
60+
package com.javarush.task.task14.task1411;
61+
62+
public interface Person {
63+
class User implements Person {
64+
void live() {
65+
System.out.println("Usually I just live.");
66+
}
67+
}
68+
69+
class Loser implements Person {
70+
void doNothing() {
71+
System.out.println("Usually I do nothing.");
72+
}
73+
}
74+
75+
class Coder implements Person {
76+
void coding() {
77+
System.out.println("Usually I create code.");
78+
}
79+
}
80+
81+
class Proger implements Person {
82+
void enjoy() {
83+
System.out.println("Wonderful life!");
84+
}
85+
}
86+
}
87+
-------------------------------------------------------------------------------------------------------------------------------------
88+
89+
90+
91+
92+
/*
93+
User, Loser, Coder and Proger
94+
1. Ввести [в цикле] с клавиатуры несколько строк (ключей).
95+
Строки(ключи) могут быть такими: «user«, «loser«, «coder«, «proger«.
96+
Ввод окончен, когда строка не совпадает ни с одной из выше указанных.
97+
98+
2. Для каждой введенной строки нужно:
99+
2.1. Создать соответствующий объект [см. Person.java], например, для строки «user» нужно создать объект класса User.
100+
2.2. Передать этот объект в метод doWork.
101+
102+
3. Написать реализацию метода doWork, который:
103+
3.1. Вызывает метод live() у переданного обекта, если этот объект (person) имеет тип User.
104+
3.2. Вызывает метод doNothing(), если person имеет тип Loser.
105+
3.3. Вызывает метод coding(), если person имеет тип Coder.
106+
3.4. Вызывает метод enjoy(), если person имеет тип Proger.
107+
108+
109+
Требования:
110+
1. Метод main должен считывать строки с клавиатуры.
111+
2. Метод main должен прекращать считывать строки с клавиатуры, как только введенная строка не совпадает с одной из ожидаемых(user, loser, coder, proger).
112+
3. Для каждой корректной(user, loser, coder, proger) введенной строки должен быть вызван метод doWork с соответствующим объектом класса Person в качестве параметра.
113+
4. В классе Solution должен быть реализован метод doWork с одним параметром типа Person.
114+
5. Метод doWork должен вызывать метод live() у переданного объекта, если этот объект имеет тип User.
115+
6. Метод doWork должен вызывать метод doNothing() у переданного объекта, если этот объект имеет тип Loser.
116+
7. Метод doWork должен вызывать метод coding() у переданного объекта, если этот объект имеет тип Coder.
117+
8. Метод doWork должен вызывать метод enjoy() у переданного объекта, если этот объект имеет тип Proger.
118+
119+
120+
------------------------------------------------Solution.java------------------------------------------------------------------------
121+
package com.javarush.task.task14.task1411;
122+
123+
import java.io.BufferedReader;
124+
import java.io.InputStreamReader;
125+
126+
/*
127+
User, Loser, Coder and Proger
128+
*/
129+
130+
public class Solution {
131+
public static void main(String[] args) throws Exception {
132+
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
133+
Person person = null;
134+
String key = null;
135+
136+
//тут цикл по чтению ключей, пункт 1
137+
{
138+
//создаем объект, пункт 2
139+
140+
doWork(person); //вызываем doWork
141+
142+
}
143+
}
144+
145+
public static void doWork(Person person) {
146+
// пункт 3
147+
}
148+
}
149+
-------------------------------------------------------------------------------------------------------------------------------------
150+
151+
152+
------------------------------------------------Person.java--------------------------------------------------------------------------
153+
package com.javarush.task.task14.task1411;
154+
155+
public interface Person {
156+
class User implements Person {
157+
void live() {
158+
System.out.println("Usually I just live.");
159+
}
160+
}
161+
162+
class Loser implements Person {
163+
void doNothing() {
164+
System.out.println("Usually I do nothing.");
165+
}
166+
}
167+
168+
class Coder implements Person {
169+
void coding() {
170+
System.out.println("Usually I create code.");
171+
}
172+
}
173+
174+
class Proger implements Person {
175+
void enjoy() {
176+
System.out.println("Wonderful life!");
177+
}
178+
}
179+
180+
}
181+
182+
-------------------------------------------------------------------------------------------------------------------------------------
183+
184+
185+
*/

0 commit comments

Comments
 (0)