-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch.java
More file actions
71 lines (68 loc) · 2.73 KB
/
Search.java
File metadata and controls
71 lines (68 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package contacts_list;
import java.util.Scanner;
public class Search extends Contact{
public static void search() throws Exception{
Scanner in = new Scanner(System.in);
Contacts = ReadFromFile.read();
Menu.searchMenu();
try{
Integer input = Integer.parseInt(in.nextLine());
if (input == 1) {
System.out.print("Név: ");
String searchedName = in.nextLine();
String[] namePieces = searchedName.split(" ");
String searchedLastName = namePieces[0];
String searchedFirstName = namePieces[1];
for (Contact i : Contacts) {
if (i.lastName.equals(searchedLastName) && i.firstName.equals(searchedFirstName)) {
System.out.println(i.toString());
}
else{
throw new InvalidNameException(searchedName);
}
}
}
else if (input == 2) {
System.out.print("Becenév: ");
String searchedNickname = in.nextLine();
for (Contact i : Contacts){
if (i.nickname.equals(searchedNickname)){
System.out.println(i.toString());
}
else {
throw new InvalidNicknameException(searchedNickname);
}
}
}
else if (input == 3) {
System.out.print("Cím: ");
String searchedAddress = in.nextLine();
for (Contact i : Contacts){
if (i.address.equals(searchedAddress)){
System.out.println(i.toString());
}
else {
throw new InvalidAddressException(searchedAddress);
}
}
}
else if (input == 4) {
System.out.print("Telefonszám: ");
String searchedNumber = in.nextLine();
for (Contact i : Contacts){
if (i.privatePhoneNumber.equals(searchedNumber) || i.workPhoneNumber.equals(searchedNumber)){
System.out.println(i.toString());
}
else {
throw new InvalidPhoneNumberException(searchedNumber);
}
}
}
Menu.mainMenu();
}
catch (NumberFormatException n){
System.out.println("Helytelen beviteli formátum! Elfogadott: [1-4]");
Menu.searchMenu();
}
}
}