Although I passed the task, it doesn' t work on IntelliJ (the method usunKoty() is somehow mistaken).
Could you tell me what's wrong?
My solution is attached in the comments.
Dyskutowane
Komentarze (2)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Magda
1 marca 2023, 18:10
public class Solution2 {
public static void main(String[] args) {
Set<Kot> koty = utworzKoty();
Set<Pies> psy = utworzPsy();
Set<Object> zwierzeta = dolacz(koty, psy);
printZwierzeta(zwierzeta);
usunKoty(zwierzeta, koty);
printZwierzeta(zwierzeta);
}
public static Set<Kot> utworzKoty() {
HashSet<Kot> wynik = new HashSet<Kot>();
//tutaj wpisz swój kod
wynik.add(new Kot());
wynik.add(new Kot());
wynik.add(new Kot());
wynik.add(new Kot());
return wynik;
}
public static Set<Pies> utworzPsy() {
//tutaj wpisz swój ko
Set<Pies> dogs = new HashSet<>();
dogs.add(new Pies());
dogs.add(new Pies());
dogs.add(new Pies());
return dogs;
}
public static Set<Object> dolacz(Set<Kot> koty, Set<Pies> psy) {
//tutaj wpisz swój kod
Set<Object> together = new HashSet<>();
together.addAll(koty);
together.addAll(psy);
return together;
}
public static void usunKoty(Set<Object> zwierzeta, Set<Kot> koty) {
//tutaj wpisz swój kod
zwierzeta.removeAll(koty);
}
public static void printZwierzeta(Set<Object> zwierzeta) {
//tutaj wpisz swój kod
for(Object x : zwierzeta)
{
System.out.println(x);
}
}
//tutaj wpisz swój kod
public static class Kot {
}
public static class Pies {
}
}
0
Thomas
1 marca 2023, 18:22
Works for me when I run it. It outputs 10 lines. The first 7 represent the elements of the zwierzeta set (koty and psy), the last three lines are the remaining psy.
Or do you get some other output?
0