编辑: yn灬不离不弃灬 | 2014-05-25 |
2 试题与试卷 1)Problem 类Sheet 表中的一行数据是一道试题.用Problem 类来封装 Sheet 表的基本结构,即试题, 这对于后续代码的设计是非常有利的.下列 Problem 类封装表结构,其实例是一道试题. Problem.java package ch5.data;
public class Problem { boolean isChoice;
//是否为选择题 boolean isJudge;
//是否为判断题 String content;
//题目内容 String giveChoiceA,giveChoiceB,giveChoiceC,giveChoiceD;
//提供选择 String imageName;
//题目所带的图像文件的名字 String correctAnswer= QWEQ@#$@!@#1QWEQ ;
//题目的正确答案 //用户回答的初始答案和 correctAnswer 不同,防止出题人忘记给正确答案 String userAnswer = ;
//初始值必须是不含任何字符的串 public boolean getIsChoice() { return isChoice;
} public void setIsChoice(boolean b) { isChoice = b;
} public boolean getIsJudge() { return isJudge;
} public void setIsJudge(boolean b) { isJudge = b;
} public void setContent(String c) { content = c;
} public String getContent() { return content;
} public void setCorrectAnswer(String a) { correctAnswer = a;
} public String getCorrectAnswer() { 第5章标准化试题训练系统
107 return correctAnswer;
} public void setUserAnswer(String u) { userAnswer = u;
} public String getUserAnswer() { return userAnswer;
} public void setGiveChoiceA(String a) { giveChoiceA = a;
} public String getGiveChoiceA() { return giveChoiceA;
} public void setGiveChoiceB(String b) { giveChoiceB = b;
} public String getGiveChoiceB() { return giveChoiceB;
} public void setGiveChoiceC(String c) { giveChoiceC = c;
} public String getGiveChoiceC() { return giveChoiceC;
} public void setGiveChoiceD(String d) { giveChoiceD = d;
} public String getGiveChoiceD() { return giveChoiceD;
} public void setImageName(String c) { imageName = c;
} public String getImageName() { return imageName;
} } 2)TestPaper 类 训练时需要从题库获得若干个试题,即用若干个试题组成一张试卷,这里用 TestPaper 类封装试卷,即该类的实例就是一张试卷. TestPaper.java package ch5.data;
Java 课程设计 第3版108 public class TestPaper { //试卷 private Problem [] problem=null;
//数组的每个单元存放一道试题(一个 Problem 对象) int index = -1;
String problemSource ;
//试卷的题库 public void setProblem(Problem [] problem){ this.problem = problem;
} public Problem getProblem(int i) { if(problem == null) { return null;
} if(problem.length==0){ return null;
} if(i>
=problem.length||ijava ch5.gui.AppWindow AppWindow.java package ch5.gui;
import ch5.data.GiveTestPaper;
import ch5.data.RamdomInitTestPaper;
import ch5.data.TestPaper;
import ch5.data.TeacherOne;
import ch5.view.TestPaperView;
import ch5.view.IntegrationView;
public class AppWindow { public static void main(String []args) { String testName= ;
IntegrationView integrationView = new IntegrationView();
GiveTestPaper initTestPaper = new RamdomInitTestPaper();
Java 课程设计 第3版126 //创建初始试卷对象 TestPaper testPaper= initTestPaper.getTestPaper( 题库/交通理论.xls ,5);
//得到有
5 个题目的试卷 TestPaperView testView = new TestPaperView();
testView.setTestPaper(testPaper);
//设置试卷 testView.setTeacher(new TeacherOne());
//设置阅卷老师 testName = 交通法训练 ;
testView.setTestName(testName);
testView.setTotalTime(15);
//考试时间
15 分钟 integrationView.addTestPaperView(testName,testView);