-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
116 lines (91 loc) · 3.31 KB
/
Solution.java
File metadata and controls
116 lines (91 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.javarush.task.task14.task1407;
//So then each one of us will give account of himself to God. (Romans 14:12)
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
Player and Dancer
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Person person = null;
String key;
while (!(key = reader.readLine()).equals("exit")) {
if ("player".equals(key)) {
person = new Player();
} else if ("dancer".equals(key)) {
person = new Dancer();
}
haveRest(person);
}
}
public static void haveRest(Person person) {
if (person instanceof Player) {//напишите тут ваш код
((Player)person).play();
} else if (person instanceof Dancer) {
((Dancer)person).dance();
}
}
interface Person {
}
static class Player implements Person {
void play() {
System.out.println("playing");
}
}
static class Dancer implements Person {
void dance() {
System.out.println("dancing");
}
}
}
/*
Player and Dancer
1. Подумать, что делает программа.
2. Изменить метод haveRest так, чтобы он вызывал метод
— play, если person имеет тип Player.
— dance, если person имеет тип Dancer.
Требования:
1. Класс Player должен реализовывать интерфейс Person.
2. Класс Dancer должен реализовывать интерфейс Person.
3. Метод haveRest должен вызывать метод play, если переданный ему объект является игроком(Player).
4. Метод haveRest должен вызывать метод dance, если переданный ему объект является танцором(Dancer).
5. Метод main должен считывать данные с клавиатуры.
6. Метод main должен прекращать считывать данные с клавиатуры, если введенная строка равна "exit".
package com.javarush.task.task14.task1407;
import java.io.BufferedReader;
import java.io.InputStreamReader;
*
Player and Dancer
*
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Person person = null;
String key;
while (!(key = reader.readLine()).equals("exit")) {
if ("player".equals(key)) {
person = new Player();
} else if ("dancer".equals(key)) {
person = new Dancer();
}
haveRest(person);
}
}
public static void haveRest(Person person) {
//напишите тут ваш код
}
interface Person {
}
static class Player implements Person {
void play() {
System.out.println("playing");
}
}
static class Dancer implements Person {
void dance() {
System.out.println("dancing");
}
}
}
*/