📄 choice.java
字号:
/* * ChoiceItem.java * * Created on 2003年11月5日, 下午9:13 */package romulus;/** * * @author Romulus * @version 1.0 */public class Choice implements QuestionItem { /** The ident of the choice.*/ private String ident = null; /** The number of correct answer.*/ private int rcardinality = 1; /** True if the chlice item should be shuffled.*/ private boolean shuffle = false; /** The answer of the choice. * It is the Vector of ChoiceItem selected. */ private java.util.Vector answer = new java.util.Vector(); /** The choice items.*/ private java.util.List citems ; /** The content of the question item.*/ private Content cont = null; /** Creates a new instance of ChoiceItem */ public Choice(String ident, int rca, boolean shu) throws RomulusException{ if(ident == null){ throw new RomulusException(RomulusException.IdentError); } this.ident = ident; this.rcardinality = rca; this.shuffle = shu; if(shu){ citems = new RandomList(); } else{ citems = new java.util.Vector(); } } /** Add and remove the choiceitem.*/ void addChoiceItem(ChoiceItem ci){ this.citems.add(ci); } boolean removeChoiceItem(ChoiceItem ci){ return this.citems.remove(ci); } public java.util.Iterator choiceitemIterator(){ return citems.iterator(); } /** Add and remove the answer.*/ public void addAnswer(ChoiceItem ci){ this.answer.add(ci); } public void clearAnswer(){ this.answer.clear(); } public boolean removeAnswer(ChoiceItem ci){ return this.answer.remove(ci); } public java.util.Iterator answerIterator(){ return answer.iterator(); } public java.util.AbstractList answerList(){ return answer; } /** * Such method is used to check the correct of the question item. */ public boolean isCorrect() { java.util.Iterator ite = citems.iterator(); ChoiceItem citem = null; java.util.Vector canswer = new java.util.Vector(); //get all of the correct answer while(ite.hasNext()){ citem = (ChoiceItem)ite.next(); if(citem.isCorrect()){ canswer.add(citem); } } //check all the correct answers are selected and all the selected answer is correct. return canswer.containsAll(answer)&&answer.containsAll(canswer); } public Content getContent(){ return this.cont; } void setContent(Content c){ this.cont = c; } /** get information*/ public String getIdent(){ return this.ident; } public int getRcardinality(){ return this.rcardinality; } public boolean isShuffle(){ return this.shuffle; } /** The method used to accept the Visitor to do something. */ public void Accept(Visitor v) throws java.sql.SQLException, RomulusException{ v.VisitQuestionItem(this); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -