-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMapStudentEx.java
More file actions
46 lines (40 loc) · 1.27 KB
/
Copy pathHashMapStudentEx.java
File metadata and controls
46 lines (40 loc) · 1.27 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
package generics;
import java.util.HashMap;
import java.util.Scanner;
class Student {
private int id;
private String tel;
public Student(int id, String tel) {
this.id = id;
this.tel = tel;
}
public int getId() {
return id;
}
public String getTel() {
return tel;
}
}
public class HashMapStudentEx {
public static void main(String[] args) {
HashMap<String, Student> map = new HashMap<String, Student>();
map.put("황기태", new Student(1, "010 - 1111 - 1111"));
map.put("이재문", new Student(2, "010 - 2222 - 2222"));
map.put("김남윤", new Student(3, "010 - 3333 - 3333"));
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.print("검색할 이름 >>> ");
String name = scanner.nextLine();
if (name.equals("exit")) {
System.out.println("종료합니다...");
break;
}
Student student = map.get(name);
if(student == null)
System.out.println(name + "은 없는 사람입니다.");
else
System.out.println("id : " + student.getId() + ", 전화 : " + student.getTel());
}
scanner.close();
}
}