Last active
November 7, 2017 04:30
-
-
Save nvlong198/f76d14676a91b7345ee7f1ff5f18e1cf to your computer and use it in GitHub Desktop.
Sample
This file contains hidden or 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 main { | |
public static void main(String[] args){ | |
theme a = new theme(); | |
// Word w; | |
ArrayList<Word> wordList1 = new ArrayList(); | |
ArrayList<Word> wordList2 = new ArrayList(); | |
wordList1.add(new Word("yellow","Vàng") ); | |
wordList1.add(new Word("red","Đỏ")); | |
wordList1.add(new Word("green","Xanh")); | |
wordList1.add(new Word("black", "Đen")); | |
wordList2.add(new Word("yellow", "Vàng" )); | |
wordList2.add(new Word("red", "Đỏ")); | |
wordList2.add(new Word("white", "Xanh")); | |
wordList2.add(new Word("black", "Đen")); | |
/** | |
không thể dùng removeAll để xóa đối tượng | |
chỉ dùng được khi khai báo ArrayList là String, Interger.... | |
*/ | |
for(int i = 0; i < wordList1.size(); i++) { | |
for(int j = i; j < wordList2.size(); j++){ | |
if( wordList1.get(i).getWord() == wordList2.get(j).getWord() ) | |
wordList1.remove(wordList1.get(i)); | |
} | |
} | |
wordList1.addAll(wordList2); | |
for(Word w: wordList1){ | |
System.out.printf("%s\t\n", w.getWord()); | |
} | |
// a.add("red","màu đỏ"); | |
// a.add("green","màu tím"); | |
// a.add("pink","màu hồng"); | |
// a.edit("green","màu xanh lá xây"); | |
// a.show(); | |
} | |
} |
This file contains hidden or 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; | |
/** | |
* @author lvip300 | |
*/ | |
public class theme { | |
private int themeid; | |
ArrayList<Word> wordList = new ArrayList(); | |
private Word aWord; | |
theme(){ | |
// contructor | |
} | |
theme(int _themeid, String _word, String _mean){ | |
this.themeid = _themeid; | |
aWord = new Word(_word,_mean); | |
wordList.add(aWord); // them vao list | |
} | |
// thêm từ input là từ và nghĩa | |
public void add(String _word, String _mean){ | |
wordList.add(new Word(_word,_mean)); | |
} | |
// xóa từ , input là từ cần xóa | |
public void remove(String input){ | |
//int size = wordList.size(); | |
for (int i = 0; i < wordList.size(); i++) { // vòng lặp foreach, w chạy từ đầu List đến cuối list | |
if( wordList.get(i).getWord()== input ) | |
wordList.remove(wordList.get(i)); | |
} | |
} | |
/** | |
* method sửa từ | |
* @param input từ cần sửa | |
* @param content nội dung | |
*/ | |
public void edit(String input, String content){ | |
for (Word w: wordList){ // vòng lặp for each | |
if( w.getWord()== input ){ | |
w.setNewDefinitionText(content); | |
} | |
} | |
} | |
public int getThemeid() { | |
return themeid; | |
} | |
//public static void display() | |
public void show(){ | |
for(Word w: wordList){ | |
System.out.printf("%s\t%s\n", w.getWord(), w.getMind()); | |
} | |
} | |
} |
This file contains hidden or 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 { | |
private String word; // từ | |
private String mind; // nghĩa | |
Word(){ //contructor | |
this.word = ""; | |
this.mind = ""; | |
} | |
Word(String _word,String _mind){ | |
this.word = _word; | |
this.mind = _mind; | |
} | |
public String getWord(){ | |
return this.word; | |
} | |
public String getMind(){ | |
return this.mind; | |
} | |
public void setNewWord(String _word){ | |
this.word = _word; | |
} | |
public void setNewDefinitionText(String _mind){ | |
this.mind = _mind; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment