Created
September 24, 2020 02:16
-
-
Save nqchieutb01/166cfeaaaf36b1a1ca3de3b66f26529b to your computer and use it in GitHub Desktop.
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
import java.util.ArrayList; | |
public class Dictionary{ | |
public static ArrayList<Word> Dictionary = new ArrayList<>() ; | |
} |
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
import java.io.FileNotFoundException; | |
public class DictionaryCommandline extends DictionaryManagement { | |
public void showAllWords(){ | |
System.out.printf("%-15s %-20s %-15s%n", "No", "English", "Vietnamese"); | |
for(int i=0;i< Dictionary.size();i++){ | |
System.out.printf("%-15d %-20s %-15s%n",i+1,Dictionary.get(i).word_target , Dictionary.get(i).word_explain); | |
} | |
} | |
public void dictionaryBasic(){ | |
// insertFromCommandline(); | |
try { | |
insertFromFile(); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
showAllWords(); | |
} | |
public static void main(String[] args) { | |
DictionaryCommandline myDictionary = new DictionaryCommandline(); | |
myDictionary.dictionaryBasic(); | |
} | |
} |
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
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.Scanner; | |
public class DictionaryManagement extends Dictionary { | |
public void insertFromCommandline(){ | |
Scanner scanner = new Scanner(System.in) ; | |
int numberOfWords = scanner.nextInt() ; | |
scanner.nextLine() ; | |
for(int i=0;i<numberOfWords;i++) { | |
String wordTarget = scanner.nextLine(); | |
String wordMean = scanner.nextLine(); | |
this.Dictionary.add(new Word(wordTarget,wordMean)) ; | |
} | |
} | |
public void insertFromFile() throws FileNotFoundException { | |
File myfile = new File("C:\\Users\\Admin\\IdeaProjects\\Dictionary\\Dictionary.txt") ; | |
Scanner scanner = new Scanner(myfile) ; | |
while (scanner.hasNext()){ | |
String[] data = scanner.nextLine().split("\\s"); | |
Word word = new Word(); | |
word.word_target = data[0] ; | |
for(int i=1;i<data.length;i++) word.word_explain += data[i]+" " ; | |
Dictionary.add(word) ; | |
} | |
} | |
} |
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
public class Word { | |
public String word_target ; | |
public String word_explain ; | |
public Word(String word_target, String word_explain){ | |
this.word_target = word_target ; | |
this.word_explain = word_explain ; | |
} | |
public Word(){ | |
this.word_target = ""; | |
this.word_explain =""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment