Chapater10 P321 標準化考試

03.*    
04.* 程序的版權和版本聲明部分    
05.* Copyright (c)2013, 煙臺大學計算機學院學生    
06.* All rightsreserved.    
07.* 文件名稱:    
08.* 作者:袁靜    
09.* 完成日期: 2013年11月17日    
10.* 版本號: v1.0    
11.* 輸入描述:無    
12.* 問題描述    
13.* 程序輸出:    
14.*/    
15.    
16.  
17.\\  
18.package Example10_20;  
19.import java.io.*;  
20.public class Test {  
21.      
22.    public static void main (String []args){  
23.        StandardExam exam=new StandardExam();  
24.        File f=new File("test.txt");  
25.        exam.setTestFile(f);  
26.        exam.startExamine();  
27.    }  
28.  
29.}  
30.  
31.  
32.  
33.  
34.  
35.  
36.package Example10_20;  
37.import java.io.*;  
38.import java.util.*;  
39.public class StandardExam {  
40.      
41.    File testFile;  
42.    public void setTestFile(File f){  
43.        testFile=f;  
44.          
45.    }  
46.    public void startExamine(){  
47.        int score=0;  
48.        Scanner scanner=new Scanner(System.in);  
49.        try{  
50.            FileReader  inOne= new FileReader(testFile);  
51.            BufferedReader inTwo=new BufferedReader(inOne);  
52.            String s=null;  
53.            while((s=inTwo.readLine())!=null){  
54.                if(!s.startsWith("-")){  
55.                    System.out.println(s);  
56.                      
57.                      
58.                }  
59.                else{  
60.                    s=s.replaceAll("-", "");  
61.                    String correctAnswer=s;  
62.                    System.out.printf("\n輸入選擇題的答案:");  
63.                    String answer=scanner.nextLine();  
64.                    if(answer.compareToIgnoreCase(correctAnswer)==0)  
65.                        score++;  
66.                    }  
67.                      
68.                }  
69.            inTwo.close();  
70.              
71.              
72.        }  
73.        catch(IOException xp){}  
74.          
75.        System.out.printf("最後得分是%d\n:",score);  
76.    }  
77.  
78.}  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章