import java.util.ArrayList;
import java.util.List;

interface Animal {	// 动物
    public String getName() ;
    public int getAge() ;
}
class Zoo {
    private List<Animal> animals = new ArrayList<Animal>() ;	// 多个动物
    public void add(Animal ani) {	// 增加动物
        this.animals.add(ani) ;	// 增加动物
    }
    public void delete(Animal ani) {
        this.animals.remove(ani) ;	// 需要equals()
    }
    public List<Animal> search(String keyWord) {
        List<Animal> result = new ArrayList<Animal>() ;
        for (int x = 0 ; x < this.animals.size() ; x ++) {
            Animal ani = this.animals.get(x) ;
            if (ani.getName().contains(keyWord)) {	// 满足
                result.add(ani) ;
            }
        }
        return result ;
    }
}
class Dog implements Animal {
    private String name ;
    private int age ;
    public Dog(String name,int age) {
        this.name = name ;
        this.age = age ;
    }
    public String getName() {
        return this.name ;
    }
    public int getAge() {
        return this.age ;
    }
    public boolean equals(Object obj) {
        if (this == obj) {
            return true ;
        }
        if (obj == null) {
            return false ;
        }
        if (!(obj instanceof Dog)) {
            return false ;
        }
        Dog dog = (Dog) obj ;
        if (this.name.equals(dog.name)
                && this.age == dog.age) {
            return true ;
        }
        return false ;
    }
    public String toString() {
        return "〖狗的信息〗名字:" + this.name + ",年龄:" + this.age ;
    }
}
class Tiger implements Animal {
    private String name ;
    private int age ;
    public Tiger(String name,int age) {
        this.name = name ;
        this.age = age ;
    }
    public String getName() {
        return this.name ;
    }
    public int getAge() {
        return this.age ;
    }
    public boolean equals(Object obj) {
        if (this == obj) {
            return true ;
        }
        if (obj == null) {
            return false ;
        }
        if (!(obj instanceof Tiger)) {
            return false ;
        }
        Tiger t = (Tiger) obj ;
        if (this.name.equals(t.name)
                && this.age == t.age) {
            return true ;
        }
        return false ;
    }
    public String toString() {
        return "〖老虎的信息〗名字:" + this.name + ",年龄:" + this.age ;
    }
}
public class Demo01 {
    public static void main(String args[]) {
        Zoo zoo = new Zoo();    // 动物园
        zoo.add(new Dog("花狗", 1));
        zoo.add(new Dog("黄狗", 1));
        zoo.add(new Dog("黑狗", 1));
        zoo.add(new Dog("斑点狗", 1));
        zoo.add(new Tiger("斑点虎", 2));
        zoo.add(new Tiger("黑虎", 2));
        zoo.add(new Tiger("花虎", 2));
        zoo.delete(new Dog("斑点狗", 1));    // 删除
        List<Animal> result = zoo.search("斑点");
        for (int x = 0; x < result.size(); x++) {
            System.out.println(result.get(x));
        }
    }
}