why is not working ,I added all animal into hashSet<>result
package com.codegym.task.task08.task0820;
import java.util.*;
/*
Animal set
*/
public class Solution {
public static void main(String[] args){
Set<Cat> cats = createCats();
Set<Dog> dogs = createDogs();
Set<Object> pets = join(cats, dogs);
printPets(pets);
removeCats(pets, cats);
printPets(pets);
}
public static Set<Cat> createCats() {
Cat cat1 = new Cat();
Cat cat2 = new Cat();
Cat cat3 = new Cat();
Cat cat4= new Cat();
Set<Cat> set = new HashSet<Cat>(Arrays.asList(cat1,cat2,cat3,cat4));
return set;
//write your code here
}
public static Set<Dog> createDogs() {
//write your code here
Dog dog1 = new Dog();
Dog dog2 = new Dog();
Dog dog3 = new Dog();
Set<Dog> set = new HashSet<Dog>(Arrays.asList(dog1,dog2,dog3));
return set;
}
public static Set<Object> join(Set<Cat> cats, Set<Dog> dogs) {
//write your code here
HashSet<Object> result = new HashSet<Object>();
Collections.addAll(result,cats);
Collections.addAll(result,dogs);
return result;
}
public static void removeCats(Set<Object> pets, Set<Cat> cats) {
//write your code here
ArrayList<Object> list = new ArrayList<Object>(4);
list.addAll(cats);
Iterator<Object> itr = pets.iterator();
while (itr.hasNext())
{
Object obj = itr.next();
for (Object listObj : list)
{
if (obj.equals(listObj))
{
itr.remove();
}
}
}
}
public static void printPets(Set<Object> pets) {
//write your code here
pets.forEach(System.out::println);
}
//write your code here
public static class Cat{
public Cat(){}
}
public static class Dog {
public Dog (){}
}
}