Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first code for 3 lesson #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/main/java/Dictionary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.util.*;

public class Dictionary {

List<String> words;

Dictionary(List<String> words){
this.words = words;
}

public Set getUniqueValues(){
Set values = new HashSet(words);
return values;
}

public Map<String,Integer> getCountOfValues(){
Map<String,Integer> values = new HashMap();

for (int i=0;i<words.size();i++){
Integer count = values.getOrDefault(words.get(i),0);
values.put(words.get(i),++count);
}return values;
}
}
23 changes: 23 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
public static void main(String[] args) {
List<String> words = new ArrayList<>(Arrays.asList("cat","dog","lion",
"elephant","gepard","fish",
"fish","cat","dog","dog"));

Dictionary dictionary = new Dictionary(words);

System.out.println(dictionary.getUniqueValues());
System.out.println(dictionary.getCountOfValues());

PhoneBook phoneBook = new PhoneBook();
phoneBook.add("olga", "89233443344");
phoneBook.add("alice", "89339853344");
phoneBook.add("alice", "893392345378344");

System.out.println(phoneBook.get("alice"));
}


}
29 changes: 29 additions & 0 deletions src/main/java/PhoneBook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.*;

public class PhoneBook {

Map<String,ArrayList<String>> book;

PhoneBook(){
book = new HashMap<>();
}

void add(String name, String phone){
if (book.containsKey(name)){
ArrayList <String> values = book.get(name);
values.add(phone);
book.put(name,values);
}else{
book.put(name, new ArrayList<>(Arrays.asList(phone)));
}
}

ArrayList<String> get(String name){
ArrayList answer = new ArrayList();
if (book.containsKey(name)){
answer = book.get(name);
}else{
System.out.println("");
}return answer;
}
}