首页 > 编程 > Java > 正文

java实现背单词程序

2019-11-26 08:46:11
字体:
来源:转载
供稿:网友

本文实例为大家分享了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); } }}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表