-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDictionaryCommandline.java
95 lines (82 loc) · 3.36 KB
/
DictionaryCommandline.java
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
90
91
92
93
94
95
import java.util.*;
public class DictionaryCommandline extends DictionaryManagement{
public Scanner Scan = new Scanner(System.in);
public void showAllWords () {
System.out.printf("%-7s%-30s%-30s\n", "NO", "English", "Vietnamese");
for (int i = 0; i < Words.size(); i++) {
System.out.printf("%-7s%-30s%-30s\n", i+1, Words.get(i).getWord_target(), Words.get(i).getWord_explain());
}
}
public void showAllWords (List<Word> Words) {
System.out.printf("%-7s%-30s%-30s\n", "NO", "English", "Vietnamese");
for (int i = 0; i < Words.size(); i++) {
System.out.printf("%-7s%-30s%-30s\n", i+1, Words.get(i).getWord_target(), Words.get(i).getWord_explain());
}
}
public void dictionaryBasic() {
insertFromCommandline();
addWord();
showAllWords();
}
public void dictionaryAdvance() {
insertFromFile();
showAllWords();
addWord();
int i = Scan.nextInt();
int d = Scan.nextInt();
showAllWords(dictionarySearcher());
dictionaryLookup();
dictionaryExportToFile();
}
public List<Word> dictionarySearcher() {
System.out.println("Nhập kí tự:");
String s = Scan.nextLine();
List<Word> Searcher = new ArrayList<Word>();
for (int i = 0; i < Words.size(); i++) {
if (Words.get(i).getWord_target().startsWith(s)) {
Searcher.add(Words.get(i));
}
}
return Searcher;
}
public static void main (String[] argh) {
DictionaryCommandline dict = new DictionaryCommandline();
dict.insertFromFile();
System.out.println("Chào mừng bạn đến với ứng dụng từ điển Anh - Việt");
System.out.println("=================================================");
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Vui lòng ấn số để chọn chức năng, sau đó ấn Enter");
System.out.println("*************************************************");
System.out.println("1: Hiện danh sách từ");
System.out.println("2: Tra từ");
System.out.println("3: Tìm từ trong danh sách");
System.out.println("4: Thêm từ");
System.out.println("5: Sửa từ");
System.out.println("6: Xóa từ");
System.out.println("0: Thoát");
System.out.println("-------------------------------------------------");
int Choice = scan.nextInt();
switch (Choice) {
case 0: System.exit(0);
break;
case 1: dict.showAllWords();
break;
case 2: dict.dictionaryLookup();
break;
case 3: dict.showAllWords(dict.dictionarySearcher());
break;
case 4: dict.addWord();
dict.dictionaryExportToFile();
break;
case 5: dict.changeWord();
dict.dictionaryExportToFile();
break;
case 6: dict.deleteWord();
dict.dictionaryExportToFile();
break;
default: break;
}
}
}
}