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