diff --git a/Animal.java b/Animal.java new file mode 100644 index 0000000..377cdfc --- /dev/null +++ b/Animal.java @@ -0,0 +1,47 @@ +public class Animal{ + private String name; + private int age; + private String ability; + private int height; + + public int getHeight() { + return this.height; + } + + public void setHeight(int height) { + this.height = height; + } + + public String getAbility() { + return this.ability; + } + + public void setAbility(String ability) { + this.ability = ability; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return this.age; + } + + public void setAge(int age) { + this.age = age; + } + + public Animal(String name , int age ,int height ,String ability){ + this.name = name; + this.age = age; + this.ability = ability; + this.height = height; + } + public void Show(){ + System.out.println("name : " + name + " , age : " + age + " , height of fly/speed : " + height + " , " + ability); + } +} \ No newline at end of file diff --git a/Bird.java b/Bird.java new file mode 100644 index 0000000..dc72241 --- /dev/null +++ b/Bird.java @@ -0,0 +1,6 @@ +public class Bird extends Animal { + + public Bird( String name , int age , int height ,String ability){ + super(name,age , height , ability); + } +} diff --git a/Cheetah.java b/Cheetah.java new file mode 100644 index 0000000..41eab0b --- /dev/null +++ b/Cheetah.java @@ -0,0 +1,5 @@ +public class Cheetah extends Mammal implements Hunter{ + public Cheetah(String name , int age , int speed, String ability){ + super(name,age ,speed , ability); + } +} diff --git a/Eagle.java b/Eagle.java new file mode 100644 index 0000000..e9fcc47 --- /dev/null +++ b/Eagle.java @@ -0,0 +1,10 @@ +public class Eagle extends Bird implements Hunter{ + + public Eagle(String name , int age , int height, String ability){ + super(name,age , height , ability); + } + + public void hunt(Prey prey){ + System.out.println(getName() + " hunted " + prey.getName()); + } +} diff --git a/Girafe.java b/Girafe.java new file mode 100644 index 0000000..d1c12b0 --- /dev/null +++ b/Girafe.java @@ -0,0 +1,6 @@ +public class Girafe extends Mammal implements Prey{ + + public Girafe(String name , int age , int speed, String ability){ + super(name,age ,speed , ability); + } +} diff --git a/Hunter.java b/Hunter.java new file mode 100644 index 0000000..6d8780d --- /dev/null +++ b/Hunter.java @@ -0,0 +1,3 @@ +public interface Hunter { + public void hunt(Prey prey); +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..9b517d5 --- /dev/null +++ b/Main.java @@ -0,0 +1,33 @@ +import java.util.ArrayList; + +public class Main { + public static void main(String[] args) { + ArrayList animals = new ArrayList<>(); + Eagle eagle1 = new Eagle("eagle1" , 15 , 50 , "Strong"); + Eagle eagle2 = new Eagle("eagle2" , 10 , 80 , "fly so high"); + Girafe girafe1 = new Girafe("girafe1" , 20 , 30 , "too tall"); + Girafe girafe2 = new Girafe("girafe2" , 25 , 25 , "just eat vegetables"); + Parrot parrot1 = new Parrot("parrot1" , 5 , 20 , "have good sound"); + Parrot parrot2 = new Parrot("parrot2" , 7 , 25 , "so beautiful"); + Cheetah cheetah1 = new Cheetah("cheetah1" , 10 , 150 , "the fastest"); + Cheetah cheetah2 = new Cheetah("cheetah2" , 15 , 120 , "cheeath coder"); + animals.add(eagle1); + animals.add(eagle2); + animals.add(girafe1); + animals.add(girafe2); + animals.add(parrot1); + animals.add(parrot2); + animals.add(cheetah1); + animals.add(cheetah2); + int num = 1; + for(Animal i : animals){ + System.out.print(num + " : "); + i.Show(); + num++; + } + System.out.println("success"); + eagle1.hunt(parrot1); + + + } +} diff --git a/Mammal.java b/Mammal.java new file mode 100644 index 0000000..3a605cd --- /dev/null +++ b/Mammal.java @@ -0,0 +1,6 @@ +public class Mammal extends Animal{ + + public Mammal(String name , int age , int speed , String ability){ + super(name,age ,speed , ability); + } +} diff --git a/Parrot.java b/Parrot.java new file mode 100644 index 0000000..451654f --- /dev/null +++ b/Parrot.java @@ -0,0 +1,6 @@ +public class Parrot extends Bird implements Prey{ + + public Parrot(String name , int age , int height, String ability){ + super(name,age , height , ability); + } +} diff --git a/Prey.java b/Prey.java new file mode 100644 index 0000000..6489291 --- /dev/null +++ b/Prey.java @@ -0,0 +1,4 @@ +public interface Prey { + public String getName(); + +}