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.}
Chapater10 P321 标准化考试
最新推荐文章于 2023-06-23 10:13:48 发布