Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

211 changes: 211 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 18 additions & 19 deletions src/main/java/com/example/Animal.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.example;

import java.util.List;

public class Animal {

public List<String> getFood(String animalKind) throws Exception {
if ("Травоядное".equals(animalKind)) {
return List.of("Трава", "Различные растения");
} else if ("Хищник".equals(animalKind)) {
return List.of("Животные", "Птицы", "Рыба");
} else {
throw new Exception("Неизвестный вид животного, используйте значение Травоядное или Хищник");
}
}

public String getFamily() {
return "Существует несколько семейств: заячьи, беличьи, мышиные, кошачьи, псовые, медвежьи, куньи";
}
package com.example;

import java.util.List;

public class Animal {

public List<String> getFood(String animalKind) throws Exception {
if ("Травоядное".equals(animalKind)) {
return List.of("Трава", "Различные растения");
} else if ("Хищник".equals(animalKind)) {
return List.of("Животные", "Птицы", "Рыба");
} else {
throw new Exception("Неизвестный вид животного, используйте значение Травоядное или Хищник");
}
}
public String getFamily() {
return "Существует несколько семейств: заячьи, беличьи, мышиные, кошачьи, псовые, медвежьи, куньи";
}
}
11 changes: 7 additions & 4 deletions src/main/java/com/example/Cat.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package com.example;

import java.util.List;

public class Cat {

private Predator predator;
private final Feline feline;

public Cat(Feline feline) {
this.predator = feline;
this.feline = feline;
}

public String getSound() {
return "Мяу";
}

public int getKittens() {
return feline.getKittens();
}

public List<String> getFood() throws Exception {
return predator.eatMeat();
return feline.eatMeat();
}
}
1 change: 1 addition & 0 deletions src/main/java/com/example/Feline.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public int getKittens() {
public int getKittens(int kittensCount) {
return kittensCount;
}

}
12 changes: 6 additions & 6 deletions src/main/java/com/example/Lion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class Lion {

private boolean hasMane;
private Feline feline;
private final boolean hasMane;

public Lion(String sex, Feline feline) throws Exception {
if ("Самец".equals(sex)) {
Expand All @@ -15,17 +15,17 @@ public Lion(String sex, Feline feline) throws Exception {
} else {
throw new Exception("Используйте допустимые значения пола животного - Самец или Самка");
}
this.feline = feline; // dependency injection
}

public int getKittens() {
return feline.getKittens();
this.feline = feline;
}

public boolean doesHaveMane() {
return hasMane;
}

public int getKittens() throws Exception {
return feline.getKittens();
}

public List<String> getFood() throws Exception {
return feline.eatMeat();
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/example/Predator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
public interface Predator {

List<String> eatMeat() throws Exception;

}
Loading