-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
89 lines (80 loc) · 2.38 KB
/
Copy pathtest.java
File metadata and controls
89 lines (80 loc) · 2.38 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mapinjava;
/**
*
* @author thien
*/
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class test {
private Map<String, String> duLieu = new TreeMap<String, String>();
// private Map<String, String> duLieu = new HashMap<String, String>();
public String themTu(String tuKhoa, String yNghia) {
return this.duLieu.put(tuKhoa, yNghia);
}
public String xoaTu(String tuKhoa) {
return this.duLieu.remove(tuKhoa);
}
public String traTu(String tuKhoa) {
String yNghia = this.duLieu.get(tuKhoa);
return yNghia;
}
public void inTuKhoa() {
Set<String> tapHopTuKhoa = this.duLieu.keySet();
System.out.println(Arrays.toString(tapHopTuKhoa.toArray()));
}
public int laySoLuong() {
return this.duLieu.size();
}
public void xoaTatCa() {
this.duLieu.clear();
}
public static void main(String[] args) {
TuDien tuDien = new TuDien();
int luaChon =0;
Scanner sc = new Scanner(System.in);
do {
System.out.println("---------------");
System.out.println("MENU ");
System.out.println("Tra từ điển Anh - Việt:\n"
+ "1. Thêm từ (Từ khóa, Ý nghĩa)\n"
+ "2. Xóa từ\n"
+ "3. Tìm ý nghĩa của từ khóa ⇒ Tra từ\n"
+ "4. In ra danh sách từ khóa\n"
+ "5. Lấy số lượng từ\n"
+ "6. Xóa tất cả các từ khóa\n"
+ "0. Thoát khỏi chương trình\n"
+ "");
luaChon = sc.nextInt(); sc.nextLine();
if(luaChon==1) {
System.out.println("Nhập vào từ khóa: ");
String tuKhoa = sc.nextLine();
System.out.println("Nhập vào ý nghĩa: ");
String yNghia = sc.nextLine();
tuDien.themTu(tuKhoa, yNghia);
}else if(luaChon==2 || luaChon==3) {
System.out.println("Nhập vào từ khóa: ");
String tuKhoa = sc.nextLine();
if(luaChon==2) {
tuDien.xoaTu(tuKhoa);
}else {
System.out.println("Ý nghĩa là: "+ tuDien.traTu(tuKhoa));
}
}else if(luaChon==4) {
tuDien.inTuKhoa();
}else if(luaChon==5) {
System.out.println("Số lượng từ khóa là: "+tuDien.laySoLuong());
}else if(luaChon==6) {
tuDien.xoaTatCa();
}
}while(luaChon!=0);
}
}