⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readtestquestion.java

📁 考试系统
💻 JAVA
字号:


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class ReadTestquestion {
    String filename="";
    String testContent="";//读取的试题内容(每小题的内容)
    String selection="";//存放用户答案
    String correctAnswer="";//存放正确答案
    int score=0;
    
    //
    long time=0;
    boolean complete=false;//
        
    File f=null;
    FileReader in=null;
    BufferedReader bin=null;
      
    public void setFileName(String name)
    {
    	filename=name;
    	score=0;
    	selection="";
    	 try {
			if(in!=null&&bin!=null)
			 {
				 in.close() ;
				 bin.close() ;
			 }
			f=new File(filename);
			in=new FileReader(f);
			bin=new BufferedReader(in);
			correctAnswer=(bin.readLine()).trim();//读取正确答案
			
			//
			String temp=(bin.readLine() .trim());
			StringTokenizer token=new StringTokenizer(temp,":");
			int hour=Integer.parseInt( token.nextToken());
			int minute=Integer.parseInt( token.nextToken());
			int second=Integer.parseInt( token.nextToken() );
			time=1000*(hour*60*60+minute*60+second);
			System.out.println("time1="+time);
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();}		    	
    }
    
    public String getFilename()
    {
    	return filename;
    }
	
    //取试题内容
	public String getTestContent()
	{
		
		try {
			String s=null;
			StringBuffer temp=new StringBuffer();			
			if(bin!=null)
			{
			while ((s=bin.readLine())!=null)
			{
				//System.out.println(s);
				if(s.startsWith( "***"))
					break;
				temp.append("\n"+s);
				
				if(s.startsWith( "endend"))
				{
					bin.close() ;
					in.close() ;
					complete=true;
					
				}
			}
			   testContent=new String(temp);
			}
			else
			{
				testContent=new String("请选择试题文件");
			}
		} catch (FileNotFoundException e) {
			
			testContent=new String("请选择试题文件");
		} catch (IOException e) {
			testContent="当前试题为空,考试结束!";
		}
		return testContent ;
		
	}
	
	//存放用户答案
	public void setSelection(String s)
	{
		selection=selection+s;//将用户提交的答案追加在selection的后面
	}
	
	public String getMessage()
	{
		int len1=selection.length() ;
		int len2=correctAnswer.length() ;
		int len=Math.min(len1,len2);
		String message="正确答案:"+correctAnswer.substring( 0,len)+"\n"+"你的答案:"+selection+"\n";
		return message;
	}
	
	public int getScore(){
		score=0;
		int len1=selection.length() ;
		int len2=correctAnswer.length() ;
		int len=Math.min(len1,len2);
		for(int i=0;i<len;i++)
		{
			if(selection.charAt(i)==correctAnswer.charAt( i))
			{
				score++;
			}
		}
		return score;
	}
	
	//
	public long getTime()
	{
		return time;
	}
	
	public void setcomplete(boolean b)
	{
		complete=b;
	}
	
	public boolean getcomplete()
	{
		return complete;
	}
	
	public static void main(String[] args) {
		ReadTestquestion r=new ReadTestquestion();
		//r.getTestContent();
		System.out.println(r.getTestContent() );

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -