cats.removeAll(pets)
Должен удалять из множества всех котов, но валидацию почему-то все равно не проходит...package com.javarush.task.task08.task0820;
import java.util.HashSet;
import java.util.Set;
/*
Множество всех животных
*/
public class Solution {
public static class Dog{
public Dog(){}
}
public static class Cat{
public Cat(){}
}
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() {
HashSet<Cat> result = new HashSet<Cat>();
for(int x=0; x<4; x++){
result.add(new Cat());
}
return result;
}
public static Set<Dog> createDogs() {
HashSet<Dog> r = new HashSet<>();
for(int x=0; x<3; x++){
r.add(new Dog());
}
return r;
}
public static Set<Object> join(Set<Cat> cats, Set<Dog> dogs) {
HashSet<Object> set = new HashSet<>();
set.addAll(cats);
set.addAll(dogs);
return set;
}
public static void removeCats(Set<Object> pets, Set<Cat> cats) {
cats.removeAll(pets);
}
public static void printPets(Set<Object> pets) {
for(Object x:pets) System.out.println(x);
}
//напишите тут ваш код
}