diff --git a/Collection Tasks/Word_Dictionary.java b/Collection Tasks/Word_Dictionary.java new file mode 100644 index 0000000..721049d --- /dev/null +++ b/Collection Tasks/Word_Dictionary.java @@ -0,0 +1,38 @@ +import java.util.*; + +public class Word_Dictionary { + + public static void main(String[]args){ + WordDictionary dict = new WordDictionary(); + dict.addWord('a',"apple"); + dict.addWord('a',"astronaut"); + dict.addWord('b',"ball"); + dict.addWord('c',"camera"); + dict.addWord('d',"dress"); + dict.printValues('a'); + dict.printDictionay(); + } + + static class WordDictionary { + Map> word_dectionary; + public WordDictionary(){ + word_dectionary = new HashMap<>(); + for(char c='a';c<'z';c++){ + word_dectionary.put(c,new ArrayList<>()); + } + } + public void addWord(char key,String word){ + word_dectionary.get(key).add(word); + } + public void printDictionay(){ + for(Map.Entry m : word_dectionary.entrySet()){ + System.out.println(m.getKey() + ": " + m.getValue()); + } + } + public void printValues(char key){ + System.out.println(word_dectionary.get(key)); + } + } +} + + diff --git a/Collection Tasks/set.java b/Collection Tasks/set.java new file mode 100644 index 0000000..f9114e9 --- /dev/null +++ b/Collection Tasks/set.java @@ -0,0 +1,69 @@ +import java.util.*; + +public class set { + public static void main(String[] args) { + Set_operations operations = new Set_operations(); + Scanner scan = new Scanner(System.in); + int testNumber = scan.nextInt(); + + for (int i = 0; i < testNumber; i++) { + + int number_of_operations = scan.nextInt(); + + for (int j = 0; j < number_of_operations; j++) { + + String operation = scan.next(); + int number; + + switch (operation) { + case "a": + number = scan.nextInt(); + operations.addValue(number); + break; + + case "b": + operations.printSortedSet(); + break; + + case "c": + number = scan.nextInt(); + operations.removeElement(number); + break; + + case "d": + number = scan.nextInt(); + operations.findNumber(number); + break; + + case "e": + operations.getSize(); + break; + } + } + } + } + static class Set_operations{ + Set operations; + public Set_operations(){ + operations = new HashSet<>(); + } + private void addValue(int number){ + operations.add(number); + } + private void printSortedSet(){ + List sortedNumbers = new ArrayList<>(operations); + Collections.sort(sortedNumbers); + for (Integer n : sortedNumbers) System.out.print(n + " "); + System.out.println(); + } + private void removeElement(int number){ + operations.remove(number); + } + private void findNumber(int number){ + System.out.println(operations.contains(number)); + } + private void getSize(){ + System.out.println(operations.size()); + } + } +}