背单词java程序设计

山东科技大学济南校区程序设计
功能要求:可以读入一个单词表文本文件, 能够将背错的单词重复记忆,直到全记住。

package java课程设计;
import java.io.*;
import java.util.*;

public class word14T {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        File file=new File("word.txt");
        //File file1=new File("wrong.txt");
        TestWord test=new TestWord();
        test.setFile(file);//类调用setfile方法
        test.setStopTime(5);//设置中间的暂停时间
        test.startTest();
    }
}
class TestWord
{
    File file;  
    int stopTime;
    public void setFile(File f)
    {
        file=f;
    }
    public void setStopTime(int t)
    {
        stopTime=t;
    }
    public void startTest()
    {
        Scanner sc=null;

        Scanner read=new Scanner(System.in);
        try
        {


            sc=new Scanner(file);
            while(sc.hasNext())
            {

                String word=sc.next();
                System.out.println(word);//显示要背的单词
                System.out.println("给"+stopTime+"秒背单词的时间");
                Thread.sleep(stopTime*1000);//使程序休眠一段时间来背诵单词
                System.out.println("\r");
                for(int i=1;i<=50;i++)
                {
                    System.out.println("*");
                }//将前面的内容覆盖
                System.out.println("输入曾经显示的单词");
                String input=read.nextLine();//将单词读入input中
                if(input.equals(word))
                {
                    System.out.println("单词正确");//匹配两个单词是否相同
                }
                else
                {
                    while(true)//将背错的程序放在死循环中,如果正确则跳出
                    {   System.out.println("单词背错了,继续背该单词");
                    System.out.println(word);
                    FileWriter intwo=new FileWriter("wrong.txt");
                    BufferedWriter tofile=new BufferedWriter(intwo);
                    BufferedWriter out=new BufferedWriter(tofile);
                    out.write(word);
                    System.out.println("给"+stopTime+"秒背单词的时间");
                    Thread.sleep(stopTime*1000);
                    System.out.println("\r");
                    for(int i=1;i<=50;i++)
                    {
                        System.out.println("*");
                    }
                    System.out.println("输入曾经显示的单词");
                    input=read.nextLine();
                    if(input.equals(word))
                    {
                        System.out.println("单词正确");
                        break;
                    }
                }
                }
            }
        }
        catch(Exception exp)
        {
            System.out.println(exp);
        }
    }
}
  • 2
    点赞
  • 70
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值