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 + '\'' +
                    '}';
        }
    }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Victor.Chang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值