package oop.kechengsheji;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
/**加载文件*/
public class ReWord{
private String str;
public ReWord(int k){
ArrayList list=new ArrayList();
String str;
switch(k){//选择要打的文章用txt保存
case 0:str="F:\\word.txt";this.str=str;break;
case 1:str="F:\\word0.txt";this.str=str;break;
case 2:str="F:\\word1.txt";this.str=str;break;
case 3:str="F:\\word2.txt";this.str=str;break;
}
try{//用文件流读取文本内容
InputStreamReader isr=new InputStreamReader(new FileInputStream(this.str));
BufferedReader reader=new BufferedReader(isr);
String line=reader.readLine();
if(line!=null){//如果内容不为null按行读取
//System.out.println(line);
list.add(line);
System.out.println(list);
}
char[] c2=line.toCharArray();
Scanner scanner=new Scanner(System.in);
long start=System.currentTimeMillis();
System.out.println("开始打字:");//输入文字
String str2=scanner.nextLine();
double count=0;
//int count1=0;
char[] c1=str2.toCharArray();
for(int index=0;index
if(c1[index]==c2[index]){//比较你所打字与原文字体相同计数器加1
count++;
}
/*if(str2.charAt(index)==line.charAt(index)){
count++;
}*/
}
long ends=System.currentTimeMillis();
System.out.println("共耗费时间:"+(ends-start)/(60*1000)
+"分"+(ends-start)/1000+"秒"+(ends-start)%1000+"毫秒");//输出你所花费时间
double total=count/c1.length;
System.out.println("正确率:"+total*100+"%");//输出你打字的正确率
}catch (Exception e){
e.printStackTrace();
}
}
}
/**调试程序*/
package oop.kechengsheji;
import java.util.Scanner;
public class Wor{ public static void main(String[] argus){ Scanner scanner=new Scanner(System.in); while(true){ System.out.println("请输入你要选择的文件(0-3):"); String str=scanner.nextLine(); int k=Integer.parseInt(str); ReWord reword=new ReWord(k); System.out.println(reword); } }}