forked from Nguyendacphong09/OOP.Dictionary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryCommandline.java
More file actions
68 lines (62 loc) · 2.44 KB
/
Copy pathDictionaryCommandline.java
File metadata and controls
68 lines (62 loc) · 2.44 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
import java.util.ArrayList;
import java.util.Scanner;
public class DictionaryCommandline {
public void showAllWord() {
int sizeArrWord = Dictionary.arrWord.size();
if (Dictionary.arrWord.isEmpty()) {
System.out.println("Từ điển trống!!!");
} else {
System.out.printf("%-10s%-2s%-20s%-2s%-20s\n", "No", "|", "English", "|", "Vietnamese");
for (int i = 0; i < sizeArrWord; i++) {
System.out.printf("%-10s%-2s%-20s%-2s%-20s\n", i + 1, "|", Dictionary.arrWord.get(i).getWord_target(), "|", Dictionary.arrWord.get(i).getWord_explain());
}
}
}
public void dictionaryBasic() {
DictionaryManagement repeat = new DictionaryManagement();
repeat.insertFromCommandline();
this.showAllWord();
}
public void dictionaryAdvanced() {
DictionaryManagement repeat = new DictionaryManagement();
repeat.insertFromFile();
this.showAllWord();
repeat.dictionaryLookup();
}
public char ASC(char a) {
char b = a;
if ((a > 64) && (a < 91)) {
return (char) (b + 32);
}
return b;
}
public void dictionarySearcher() {
Scanner scan = new Scanner(System.in);
System.out.println("--------Search---------");
System.out.println("Nhập từ cần tìm: ");
ArrayList<Word> arrWordcpy = Dictionary.arrWord;
while (arrWordcpy.size() != 0 && arrWordcpy.size() != 1) {
String input = scan.nextLine();
for (int i = 0; i < Dictionary.arrWord.size(); i++) {
int lw = Dictionary.arrWord.get(i).getWord_target().length();
int linput = input.length();
int min;
if (linput > lw) {
min = lw;
} else {
min = linput;
}
for (int j = 0; j < min; j++) {
if ((ASC(input.charAt(j)) != ASC(Dictionary.arrWord.get(i).getWord_target().charAt(j))) || (linput > lw)) {
arrWordcpy.remove(arrWordcpy.get(i));
i--;
break;
}
}
}
for (int k = 0; k < arrWordcpy.size(); k++) {
System.out.println(arrWordcpy.get(k).getWord_target());
}
}
}
}