diff --git a/lesson2/pom.xml b/lesson2/pom.xml new file mode 100644 index 0000000..1386dfe --- /dev/null +++ b/lesson2/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + ru.gb.savilin + lesson2 + 1.0-SNAPSHOT + + + 8 + 8 + + + \ No newline at end of file diff --git a/lesson2/src/main/java/Animal.java b/lesson2/src/main/java/Animal.java new file mode 100644 index 0000000..24ed811 --- /dev/null +++ b/lesson2/src/main/java/Animal.java @@ -0,0 +1,22 @@ +package main.java; + +public abstract class Animal { + + RunBehavior runBehavior; + SwimBehavior swimBehavior; + int appetite; + String name; + boolean satiety; + + public void performSwim(){ + swimBehavior.swim(); + } + + public void performRun(int distance){ + runBehavior.run(distance); + } + + public void setSatiety(boolean satiety){ + this.satiety = satiety; + } +} diff --git a/lesson2/src/main/java/AnimalManager.java b/lesson2/src/main/java/AnimalManager.java new file mode 100644 index 0000000..8d3aec5 --- /dev/null +++ b/lesson2/src/main/java/AnimalManager.java @@ -0,0 +1,19 @@ +package main.java; + +import main.java.Cat; +import main.java.Dog; + +public class AnimalManager { + + public static void getAllDogs(){ + System.out.println(Dog.getAllDogs()); + } + + public static void getAllCats(){ + System.out.println(Cat.getAllCats()); + } + + public static void getAllAnimals(){ + System.out.println(Dog.getAllDogs() + Cat.getAllCats()); + } +} diff --git a/lesson2/src/main/java/Cat.java b/lesson2/src/main/java/Cat.java new file mode 100644 index 0000000..2b9f3c3 --- /dev/null +++ b/lesson2/src/main/java/Cat.java @@ -0,0 +1,35 @@ +package main.java; + +public class Cat extends Animal{ + private static int counter = 0; + private int appetite; + private boolean satiety; + + public Cat(String name, int appetite){ + swimBehavior = new SwimNoWay(); + runBehavior = new CatRunning(); + this.name = name; + this.appetite = appetite; + this.satiety = false; + counter ++; + this.appetite = appetite; + satiety = false; + } + + public void eat(Plate p){ + if (p.getFood()= n) { + food -= n; + return true; + } else { + System.out.println("not enough food"); + } + return false; + } + + public int getFood() { + return food; + } + + public void info(){ + System.out.println("plate: " + food); + } + + public void addFood(int food){ + this.food += food; + } +} diff --git a/lesson2/src/main/java/RunBehavior.java b/lesson2/src/main/java/RunBehavior.java new file mode 100644 index 0000000..78fbdab --- /dev/null +++ b/lesson2/src/main/java/RunBehavior.java @@ -0,0 +1,5 @@ +package main.java; + +public interface RunBehavior { + public void run(int distance); +} diff --git a/lesson2/src/main/java/Swim.java b/lesson2/src/main/java/Swim.java new file mode 100644 index 0000000..3fa1977 --- /dev/null +++ b/lesson2/src/main/java/Swim.java @@ -0,0 +1,8 @@ +package main.java; + +public class Swim implements SwimBehavior{ + + public void swim(){ + System.out.println("i'm swimming"); + } +} diff --git a/lesson2/src/main/java/SwimBehavior.java b/lesson2/src/main/java/SwimBehavior.java new file mode 100644 index 0000000..ac7d85a --- /dev/null +++ b/lesson2/src/main/java/SwimBehavior.java @@ -0,0 +1,5 @@ +package main.java; + +public interface SwimBehavior { + public void swim(); +} diff --git a/lesson2/src/main/java/SwimNoWay.java b/lesson2/src/main/java/SwimNoWay.java new file mode 100644 index 0000000..fee2377 --- /dev/null +++ b/lesson2/src/main/java/SwimNoWay.java @@ -0,0 +1,7 @@ +package main.java; + +public class SwimNoWay implements SwimBehavior{ + public void swim(){ + System.out.println("i can't swim"); + } +}