Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Collection Tasks/Word_Dictionary.java
Original file line number Diff line number Diff line change
@@ -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<Character,ArrayList<String>> 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));
}
}
}


69 changes: 69 additions & 0 deletions Collection Tasks/set.java
Original file line number Diff line number Diff line change
@@ -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<Integer> operations;
public Set_operations(){
operations = new HashSet<>();
}
private void addValue(int number){
operations.add(number);
}
private void printSortedSet(){
List<Integer> 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());
}
}
}