📄 questmanager.java
字号:
import java.util.*;
import java.awt.*;
class QuestManager {
Exam GUI;
int iCurQuest=-1;
public int iQuestCount;
//vQuestObs is a vector of Question Objects
private Vector vQuestObs;
//vQuestions is a vector of Question string arrays
private Vector vQuestions;
//Constructor
QuestManager(Vector v,Exam GUIParm){
GUI = GUIParm;
vQuestions=v;
setupQuestions();
}
private void setupQuestions(){
String[] sQText = new String[vQuestions.size()];
//First two positions are for Question Text and Answer
//the rest is for options
vQuestObs = new Vector();
for(int i=0;i< vQuestions.size();i++){
try{
sQText = (String[]) vQuestions.elementAt(i);
} catch(Exception e) {System.out.println("Exception") ;}
String[] saOpt=new String[(sQText.length -2 )];;
for(int iOptCount = 2; iOptCount <sQText.length; iOptCount++){
saOpt[iOptCount-2]=sQText[iOptCount];
}
Question q = new Question();
q.setOptions(saOpt);
q.setQuestionText(sQText[0]);
q.setAnswer(sQText[1]);
vQuestObs.addElement(q);
}
//Track when we are at the end of the Questions
iQuestCount = vQuestObs.size();
}
public void getForward(){
String sQuestion;
Question q = new Question();
//Have we got the first question?
if(iCurQuest >-1){
q= (Question) vQuestObs.elementAt(iCurQuest);
//Get the current option settings
q.setResponse(GUI.pOptButtons);
//remove all of the option buttons
GUI.pOptButtons.removeAll();
}
//Stay put if at the end of Questions
if(iCurQuest < iQuestCount-1)
{
iCurQuest++;
}
q= (Question) vQuestObs.elementAt(iCurQuest);
sQuestion=q.getQuestionText();
//GUI.ta.replaceText(sQuestion,0,1000);
//Blank out current contents
GUI.ta.replaceText(sQuestion,0,GUI.ta.getText().length());
int OptionLength = sQuestion.length();
//String array of option labels
String[] saOpt=q.getOptions();
//Walk around the Option buttons
setOptButtons(saOpt,q);
//Stay put if this is the last Question
GUI.ta.select(0,0);
GUI.repaint();
GUI.pOptButtons.validate();
}
public void setOptButtons(String[] saOpt, Question q){
for( int iOptCount =0;iOptCount <saOpt.length;iOptCount++){
boolean bChkState=false;
//Get the current setting
bChkState=q.getResponse(iOptCount);
//Default is 5 options, if less dont add checkbox
if(saOpt[iOptCount] !=null){
Checkbox cb = new Checkbox();
cb.setLabel(saOpt[iOptCount]);
cb.setState(bChkState);
GUI.pOptButtons.add(cb);
}
}
}
public void getBack(){
String sQuestion;
Question q = new Question();
if(iCurQuest >0)
{
iCurQuest--;
}
q= (Question) vQuestObs.elementAt(iCurQuest);
sQuestion=q.getQuestionText();
//GUI.ta.replaceText(sQuestion,0,1000);
//Blank out current contents
GUI.ta.replaceText(sQuestion,0,GUI.ta.getText().length());
int OptionLength = sQuestion.length();
GUI.pOptButtons.removeAll();
String[] saOpt=q.getOptions();
setOptButtons(saOpt,q);
//Stay put if this is the last Question
GUI.ta.select(0,0);
GUI.repaint();
GUI.pOptButtons.validate();
}
public int getQuestCount(){
return iQuestCount;
}
public int getRightAnsCount(){
boolean bRightAns=true;
//Might get more performance by doing this only once
int iQuestCount= vQuestObs.size();
//Start off assuming every answer is correct
int iRightAnsCount=iQuestCount;
for(int i=0; i<iQuestCount;i++){
Question q = (Question) vQuestObs.elementAt(i);
boolean bAns[]= q.getAnswer();
boolean bRes[]=q.getResponse();
bRightAns=true;
//Compare each element of the array of booleans
for(int j=0; j< bAns.length; j++){
if(bAns[j]!=bRes[j]){
bRightAns=false;
}
}
//Do this once for eqch question
if(bRightAns==false)
iRightAnsCount--;
}
//System.out.println("Right ans count = " + iRightAnsCount);
return iRightAnsCount;
}
public boolean[] getRightAns(int iQuestNo){
Question q = (Question) vQuestObs.elementAt(iQuestNo);
boolean[] baAns=q.getAnswer();
return baAns;
}
public boolean getAnsweredRight(int iQuestNo){
Question q = (Question) vQuestObs.elementAt(iQuestNo);
boolean bAnsRight = q.getAnsweredRight();
return bAnsRight;
}
public boolean getAtttempted(int iQuestNo){
//See if any attempt has been
//made to answer this question
Question q = (Question) vQuestObs.elementAt(iQuestNo);
return q.getAttempted();
}
public int getAttemptedCount(){
int iAttemptedCount=0;
for(int i=0; i<iQuestCount;i++){
Question q = (Question) vQuestObs.elementAt(i);
if(q.getAttempted()){
iAttemptedCount++;
}//End if
//System.out.println("Attempted Count = " + iAttemptedCount);
}//End for
return iAttemptedCount;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -