Skip to content

Commit e7e7d11

Browse files
authored
Little children I will be with you 4 little while
Little children, I will be with you a little while longer. You will seek me, and as I said to the Jews, 'Where I am going, you can't come,' so now I tell you.(John 13:33)
1 parent 2318fcb commit e7e7d11

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

‎task12/task1225/Solution.java‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package com.javarush.task.task12.task1225;
2+
3+
//Little children, I will be with you a little while longer. You will seek me, and as I said to the Jews,
4+
//'Where I am going, you can't come,' so now I tell you.(John 13:33)
5+
6+
/*
7+
Посетители
8+
*/
9+
10+
public class Solution {
11+
public static void main(String[] args) {
12+
System.out.println(getObjectType(new Cat()));
13+
System.out.println(getObjectType(new Tiger()));
14+
System.out.println(getObjectType(new Lion()));
15+
System.out.println(getObjectType(new Bull()));
16+
System.out.println(getObjectType(new Cow()));
17+
System.out.println(getObjectType(new Animal()));
18+
}
19+
20+
public static String getObjectType(Object o) {
21+
if (o instanceof Tiger){return "Тигр";}//напишите тут ваш код
22+
else if (o instanceof Lion){return "Лев";}
23+
else if (o instanceof Cat){return "Кот";}
24+
else if (o instanceof Bull){return "Бык";}
25+
else if (o instanceof Cow){return "Корова";}
26+
else return "Животное";
27+
}
28+
29+
public static class Cat extends Animal //<--Классы наследуются!!
30+
{
31+
}
32+
33+
public static class Tiger extends Cat {
34+
}
35+
36+
public static class Lion extends Cat {
37+
}
38+
39+
public static class Bull extends Animal {
40+
}
41+
42+
public static class Cow extends Animal {
43+
}
44+
45+
public static class Animal {
46+
}
47+
}
48+
49+
50+
51+
/*
52+
Посетители
53+
Напиши метод, который определяет, какой объект передали в него.
54+
Программа должна выводить на экран одну из надписей:
55+
«Кот», «Тигр», «Лев», «Бык», «Корова», «Животное».
56+
57+
Замечание:
58+
постарайся определять тип животного как можно более точно.
59+
60+
61+
Требования:
62+
1. Класс Solution должен содержать классы Cat, Tiger, Lion, Bull, Cow, Animal.
63+
2. Класс Solution должен содержать метод String getObjectType(Object o).
64+
3. Метод getObjectType() должен возвращать строку «Кот» если передан объект типа Cat.
65+
4. Метод getObjectType() должен возвращать строку «Тигр» если передан объект типа Tiger.
66+
5. Метод getObjectType() должен возвращать строку «Лев» если передан объект типа Lion.
67+
6. Метод getObjectType() должен возвращать строку «Бык» если передан объект типа Bull.
68+
7. Метод getObjectType() должен возвращать строку «Животное» если передан объект типа Animal.
69+
8. Программа должна выводить на экран результат метода getObjectType().
70+
71+
package com.javarush.task.task12.task1225;
72+
73+
74+
Посетители
75+
76+
77+
public class Solution {
78+
public static void main(String[] args) {
79+
System.out.println(getObjectType(new Cat()));
80+
System.out.println(getObjectType(new Tiger()));
81+
System.out.println(getObjectType(new Lion()));
82+
System.out.println(getObjectType(new Bull()));
83+
System.out.println(getObjectType(new Cow()));
84+
System.out.println(getObjectType(new Animal()));
85+
}
86+
87+
public static String getObjectType(Object o) {
88+
//напишите тут ваш код
89+
90+
return "Животное";
91+
}
92+
93+
public static class Cat extends Animal //<--Классы наследуются!!
94+
{
95+
}
96+
97+
public static class Tiger extends Cat {
98+
}
99+
100+
public static class Lion extends Cat {
101+
}
102+
103+
public static class Bull extends Animal {
104+
}
105+
106+
public static class Cow extends Animal {
107+
}
108+
109+
public static class Animal {
110+
}
111+
}
112+
*/

0 commit comments

Comments
 (0)