ΠΠΎΡΠ΅ΠΌΡ ΡΠ°ΠΊΠΈΠΌ ΡΠΏΠΎΡΠΎΠ±ΠΎΠΌ Ρ Π½Π΅ ΠΌΠΎΠ³Ρ ΡΠΎΠ·Π΄Π°ΡΡ ΠΊΠΎΡΠΎΠ² ΠΈ ΡΠΎΠ±Π°ΠΊ?
package com.javarush.task.task08.task0820;
import java.util.HashSet;
import java.util.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() {
Set<Cat> result = new HashSet<Cat>();
int i = 0;
for(Cat cat : result){
if(i < 4){
result.add(cat);
}
}
return result;
}
public static Set<Dog> createDogs() {
Set<Dog> createDogs = new HashSet<Dog>();
int a = 0;
for(Dog dog : createDogs){
if(a < 3){
createDogs.add(dog);
}
}
return createDogs;
}
public static Set<Object> join(Set<Cat> cats, Set<Dog> dogs) {
Set<Object> join = new HashSet<Object>();
join.addAll(cats);
join.addAll(dogs);
return join;
}
public static void removeCats(Set<Object> pets, Set<Cat> cats) {
pets.removeAll(cats);
}
public static void printPets(Set<Object> pets) {
for(Object out : pets){
System.out.println(out);
}
}
public static class Cat {
public Cat(){
}
}
public static class Dog {
public Dog(){
}
}
}