forked from phuctd99/TrainnerDic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TranDuyPhuc
authored and
TranDuyPhuc
committed
Sep 29, 2018
0 parents
commit 96cbaaf
Showing
14 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Dictionary_Java_oop</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
2 changes: 2 additions & 0 deletions
2
Dictionary_Java_oop/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/dictionary/DictionaryManagement.java=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
home ngoi nha | ||
beach bai bien | ||
dog con cho |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|0 |home |ngoi nha | ||
|1 |beach |bai bien | ||
|2 |dog |con cho |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dictionary; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Dictionary { | ||
//listWord de luu mang Word | ||
static ArrayList<Word> listWord = new ArrayList<Word>(); | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
Dictionary_Java_oop/src/dictionary/DictionaryCommandline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dictionary; | ||
import dictionary.DictionaryManagement; | ||
|
||
import dictionary.Dictionary; | ||
|
||
public class DictionaryCommandline { | ||
DictionaryManagement dictionarymanagement = new DictionaryManagement(); | ||
public void showAllWord(){ | ||
System.out.println("|No |English |Vietnamese"); | ||
for (int i = 0; i < Dictionary.listWord.size(); i++) { | ||
Word word = Dictionary.listWord.get(i); | ||
System.out.println(i+" "+word.getWord_target()+" " | ||
+word.getWord_explain()); | ||
} | ||
} | ||
public void dictionaryBasic(){ | ||
dictionarymanagement.insertFromCommandline(); | ||
showAllWord(); | ||
} | ||
public void dictionaryAdvanced(){ | ||
//dictionarymanagement.insertFromCommandline(); | ||
dictionarymanagement.insertFromFile(); | ||
dictionarymanagement.dictionaryExportToFile(); | ||
showAllWord(); | ||
dictionarymanagement.dictionaryLookup(); | ||
} | ||
public static void main(String [] args){ | ||
DictionaryCommandline dicCommand = new DictionaryCommandline(); | ||
dicCommand.dictionaryAdvanced(); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
Dictionary_Java_oop/src/dictionary/DictionaryManagement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package dictionary; | ||
import dictionary.Dictionary; | ||
import java.io.BufferedReader; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintWriter; | ||
import java.util.Scanner; | ||
import dictionary.Word; | ||
|
||
public class DictionaryManagement { | ||
Scanner sc = new Scanner(System.in); | ||
|
||
public void insertFromCommandline(){ | ||
System.out.println("Nhap so luong tu: "); | ||
int numberWord = sc.nextInt(); | ||
sc.nextLine(); | ||
// sc.nextLine() de doc not ki tu "\n" khi nhap sc.nextInt() | ||
for(int i=0; i<numberWord; i++){ | ||
System.out.println("Nhap tu: "); | ||
String word_target = sc.nextLine(); | ||
System.out.println("Giai nghia: "); | ||
String word_explain = sc.nextLine(); | ||
Word word = new Word(word_target, word_explain); | ||
Dictionary.listWord.add(word); | ||
} | ||
} | ||
public void dictionaryLookup(){ | ||
System.out.println("nhap tu can tra: "); | ||
String wordLookup = sc.nextLine(); | ||
for (int i = 0; i < Dictionary.listWord.size(); i++) { | ||
Word word = Dictionary.listWord.get(i); | ||
if((word.getWord_target()).equals(wordLookup)){ | ||
System.out.println("Find sucess!"); | ||
System.out.println(word.getWord_target()+" "+word.getWord_explain()); | ||
} | ||
else{ | ||
System.out.println("Find failed!"); | ||
} | ||
} | ||
} | ||
public void insertFromFile(){ | ||
try { | ||
FileInputStream fis = new FileInputStream("Dictionary.txt"); | ||
InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); | ||
BufferedReader br = new BufferedReader(isr); | ||
// gán dòng 1 cho line | ||
String line = br.readLine(); | ||
while(line != null) { | ||
String []arr = line.split("\t");//tach thanh cac phan tu | ||
Word tu = new Word(arr[0],arr[1]); | ||
Dictionary.listWord.add(tu); | ||
line = br.readLine(); //doc ki tu "\n" | ||
} | ||
br.close(); | ||
isr.close(); | ||
fis.close(); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
public void dictionaryExportToFile(){ | ||
try { | ||
FileOutputStream fos = new FileOutputStream("OutputFile.txt"); | ||
PrintWriter out = new PrintWriter(fos); | ||
for(int i=0; i<Dictionary.listWord.size();i++){ | ||
Word word = Dictionary.listWord.get(i); | ||
out.printf("|%d\t|%s\t|%s\n",i,word.getWord_target(),word.getWord_explain()); | ||
} | ||
out.close(); | ||
} catch (FileNotFoundException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dictionary; | ||
|
||
public class Word { | ||
private String word_target; | ||
private String word_explain; | ||
public String getWord_target() { | ||
return word_target; | ||
} | ||
public void setWord_target(String word_target) { | ||
this.word_target = word_target; | ||
} | ||
public String getWord_explain() { | ||
return word_explain; | ||
} | ||
public void setWord_explain(String word_explain) { | ||
this.word_explain = word_explain; | ||
} | ||
//constructor | ||
public Word(String word_target, String word_explain){ | ||
this.word_target = word_target; | ||
this.word_explain = word_explain; | ||
} | ||
} |