java实现背单词程序

时间:2021-05-19

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

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

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章