Обновлены файлы
This commit is contained in:
parent
e5cd30ee29
commit
80385f3156
1
.gitignore
vendored
1
.gitignore
vendored
@ -31,6 +31,7 @@ target/
|
|||||||
build/
|
build/
|
||||||
!**/src/main/**/build/
|
!**/src/main/**/build/
|
||||||
!**/src/test/**/build/
|
!**/src/test/**/build/
|
||||||
|
/.idea
|
||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|||||||
@ -55,18 +55,19 @@ public class Zoo {
|
|||||||
|
|
||||||
worker1.getVoice(bear1);
|
worker1.getVoice(bear1);
|
||||||
worker1.getVoice(kotik1);
|
worker1.getVoice(kotik1);
|
||||||
worker2.getVoice(fish1);
|
|
||||||
|
|
||||||
Animal[] pond = createPond();
|
|
||||||
|
|
||||||
|
Swim[] pond = createPond();
|
||||||
|
|
||||||
if (pond.length > 0){
|
if (pond.length > 0){
|
||||||
|
|
||||||
System.out.println("Пруд: ");
|
System.out.println("Пруд: ");
|
||||||
|
|
||||||
for (Animal animal : pond) {
|
for (Swim swimmer : pond) {
|
||||||
if (animal.getName() != null) {
|
if (swimmer instanceof Animal) {
|
||||||
((Swim) animal).swim();
|
Animal animal = (Animal) swimmer;
|
||||||
|
if (animal.getName() != null) {
|
||||||
|
swimmer.swim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,7 +76,7 @@ public class Zoo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Animal[] createPond(){
|
public static Swim[] createPond(){
|
||||||
List<Animal> pondList = new ArrayList<>();
|
List<Animal> pondList = new ArrayList<>();
|
||||||
|
|
||||||
for (Animal animal : allAnimals) {
|
for (Animal animal : allAnimals) {
|
||||||
@ -84,6 +85,6 @@ public class Zoo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pondList.toArray(new Animal[0]);
|
return pondList.toArray(new Swim[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import food.Food;
|
|||||||
|
|
||||||
public abstract class Animal {
|
public abstract class Animal {
|
||||||
private String name;
|
private String name;
|
||||||
public int satiety;
|
int satiety;
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
return this.name;
|
return this.name;
|
||||||
|
|||||||
@ -6,6 +6,8 @@ public class Bear extends Carnivorous implements Run, Voice {
|
|||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Bear(){};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (this.getName() != null){
|
if (this.getName() != null){
|
||||||
@ -17,7 +19,7 @@ public class Bear extends Carnivorous implements Run, Voice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVoice(){
|
public Voice getVoice(){
|
||||||
return "гррр";
|
return "гррр";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@ public class Deer extends Herbivore implements Run {
|
|||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Deer(){};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (this.getName() != null){
|
if (this.getName() != null){
|
||||||
|
|||||||
@ -6,6 +6,8 @@ public class Duck extends Herbivore implements Run, Swim, Fly, Voice {
|
|||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Duck(){};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (this.getName() != null){
|
if (this.getName() != null){
|
||||||
@ -37,7 +39,7 @@ public class Duck extends Herbivore implements Run, Swim, Fly, Voice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVoice(){
|
public Voice getVoice(){
|
||||||
return "кря";
|
return "кря";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@ public class Fish extends Carnivorous implements Swim {
|
|||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Fish (){};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void swim() {
|
public void swim() {
|
||||||
if (this.getName() != null){
|
if (this.getName() != null){
|
||||||
|
|||||||
@ -6,6 +6,8 @@ public class Kotik extends Carnivorous implements Run, Voice {
|
|||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Kotik(){};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (this.getName() != null){
|
if (this.getName() != null){
|
||||||
@ -17,7 +19,7 @@ public class Kotik extends Carnivorous implements Run, Voice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVoice(){
|
public Voice getVoice(){
|
||||||
return "мяу";
|
return "мяу";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@ public class Sheep extends Herbivore implements Run, Voice {
|
|||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Sheep (){};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (this.getName() != null){
|
if (this.getName() != null){
|
||||||
@ -17,7 +19,7 @@ public class Sheep extends Herbivore implements Run, Voice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVoice(){
|
public Voice getVoice(){
|
||||||
return "бее";
|
return "бее";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
package animals;
|
package animals;
|
||||||
|
|
||||||
public interface Voice {
|
public interface Voice {
|
||||||
String getVoice();
|
Voice getVoice();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,10 +29,12 @@ public class Worker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getVoice(Animal animal){
|
public void getVoice(Voice voiceAnimal) {
|
||||||
if (this.Name != null || animal.getName() != null){
|
if (voiceAnimal instanceof Animal) {
|
||||||
if (animal instanceof Voice){
|
Animal animal = (Animal) voiceAnimal;
|
||||||
System.out.println(this.getName() + " говорит с животным: " + animal.getName() + ". Животное отвечает - "+ ((Voice) animal).getVoice() +".");
|
if (animal.getName() != null && this.Name != null) {
|
||||||
|
System.out.println(this.getName() + " говорит с животным: " + animal.getName()
|
||||||
|
+ ". Животное отвечает - " + voiceAnimal.getVoice() + ".");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println(this.getName() + " пытается говорить с животным: " + animal.getName() + ". Это животное не умеет издавать звук.");
|
System.out.println(this.getName() + " пытается говорить с животным: " + animal.getName() + ". Это животное не умеет издавать звук.");
|
||||||
@ -40,6 +42,8 @@ public class Worker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Worker(){};
|
public Worker(){};
|
||||||
|
|
||||||
public Worker(String name){
|
public Worker(String name){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user