Java 随手写的一个英语单词练习器
1.导入英文单词;
2.随机选取若干单词提问;
3.终端输入单词,判断是否作对;
4.得分显示;
import java.util.*;
/**
* @author Victor.Chang
* @date 2021/5/11 15:45
*/
public class EnglishWordTest {
private static List<Word> monthWordList = new ArrayList<>();
static {
monthWordList.add(new Word("January", "一月", ""));
monthWordList.add(new Word("February", "二月", ""));
monthWordList.add(new Word("March", "三月", ""));
monthWordList.add(new Word("April", "四月", ""));
monthWordList.add(new Word("May", "五月", ""));
monthWordList.add(new Word("June", "六月", ""));
monthWordList.add(new Word("July", "七月", ""));
monthWordList.add(new Word("August", "八月", ""));
monthWordList.add(new Word("September", "九月", ""));
monthWordList.add(new Word("October", "十月", ""));
monthWordList.add(new Word("November", "十一月", ""));
monthWordList.add(new Word("December", "十二月", ""));
}
public static void test1() {
int scores = 0;
Set<Word> set = new HashSet<>();
Scanner scan = new Scanner(System.in);
while (set.size() < 5) {
int idx = (int) (Math.random() * 12);
Word word = monthWordList.get(idx);
if (set.add(word)) {
System.out.println("请拼写" + word.getDesc() + ":");
String writeWord = scan.next();
if (writeWord.toLowerCase().equals(word.getEnglish().toLowerCase())) {
System.out.println("You Right!");
scores++;
} else {
System.out.println("You Error! The right word is " + word.getEnglish());
}
}
}
System.out.println("Your scores is " + scores);
System.out.println("Do you want test again? (yes: 1 no: ^e)");
String res = scan.next();
if ("1".equals(res)) {
test1();
} else {
System.out.println("Bye bye~");
}
}
public static void main(String[] args) {
test1();
}
private static class Word {
private String english; // 单词
private String desc; // 解释
private String speak; // 音标
public Word(String english, String desc, String speak) {
this.english = english;
this.desc = desc;
this.speak = speak;
}
public String getEnglish() {
return english;
}
public void setEnglish(String english) {
this.english = english;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getSpeak() {
return speak;
}
public void setSpeak(String speak) {
this.speak = speak;
}
@Override
public String toString() {
return "Word{" +
"english='" + english + '\'' +
", desc='" + desc + '\'' +
", speak='" + speak + '\'' +
'}';
}
}
}