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
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.

34 changes: 34 additions & 0 deletions src/main/java/lesson3/Homework/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package lesson3.Homework;

import java.util.ArrayList;

public class Main {
public static void main(String[] args) {
PhoneDirectory book = new PhoneDirectory();
book.add(new Phone("1","Суров", "89457432341"));
book.add(new Phone("2","Суров", "89457252341"));
book.add(new Phone("3","Суров", "894357432341"));
book.add(new Phone("4","Федотов", "89457433571" ));
book.add(new Phone("5","Рапницкий", "89457891341" ));
book.add(new Phone("6","Захаров", "89450002341" ));
book.get("Суров");
book.get("Карпухин");
String[] words =new String[]{"represent","represent","represent","represent","present","present","reprimand","procrastinate","present","tent","tent","reprimand","reevaluate","elevate","Rip and Tear"};
ArrayList<String> unique= new ArrayList<>();
for (int i = 0; i < 15; i++) {
if(!unique.contains(words[i])){
unique.add(words[i]);
}
}

for (String word: unique) {
int sum = 0;
for (int i = 0; i < 15; i++) {
if(words[i].equals(word)){
sum+=1;
}
}
System.out.println(word + " встречается " + sum + " раз");
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/lesson3/Homework/Phone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package lesson3.Homework;

public class Phone {
String id;
String surname;
String number;

public Phone(String id, String surname, String number) {
this.id = id;
this.surname = surname;
this.number = number;
}
}
27 changes: 27 additions & 0 deletions src/main/java/lesson3/Homework/PhoneDirectory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package lesson3.Homework;

import java.util.ArrayList;

public class PhoneDirectory {
ArrayList<Phone> phones = new ArrayList<>();

public PhoneDirectory() {
}
public void add(Phone phone){
phones.add(phone);
}
public void get(String surname){
String outPut= "";
for (Phone phone:phones) {
if(surname.equals(phone.surname)){
outPut+= " " + phone.number;
}
}
if(outPut.equals("")){
System.out.println("По фамилии " + surname + " не найдено никаких номеров");
}
else{
System.out.println("По фамилии " + surname + " найдены данные телефоны:"+outPut);
}
}
}