Created
March 20, 2015 15:52
-
-
Save shcherbakoff/3ea4be84a6a5214123fc to your computer and use it in GitHub Desktop.
package com.javarush.test.level08.lesson11.home01;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level08.lesson11.home01; | |
import java.util.HashSet; | |
import java.util.Iterator; | |
import java.util.Set; | |
/* Set из котов | |
1. Внутри класса Solution создать public static класс кот – Cat. | |
2. Реализовать метод createCats, он должен создавать множество (Set) котов и добавлять в него 3 кота. | |
3. В методе main удалите одного кота из Set cats. | |
4. Реализовать метод printCats, он должен вывести на экран всех котов, которые остались во множестве. Каждый кот с новой строки. | |
*/ | |
public class Solution | |
{ | |
public static void main(String[] args) | |
{ | |
Set<Cat> cats = createCats(); | |
Iterator<Cat> iterator = cats.iterator(); | |
if (iterator.hasNext()) | |
cats.remove(iterator.next()); | |
printCats(cats); | |
} | |
public static Set<Cat> createCats() | |
{ | |
Set<Cat> cats = new HashSet<Cat>(); | |
for (int i=0; i < 3; i++) | |
{ | |
cats.add(new Cat()); | |
} | |
return (HashSet<Cat>) cats; | |
} | |
public static void printCats(Set<Cat> cats) | |
{ | |
for (Cat cat : cats) | |
System.out.println(cat); | |
} | |
public static class Cat | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment