⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 questionbean.java

📁 老外的在线考试
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 */	public abstract boolean getMustMatchAllKeywords();		/**	 * Sets whether a keywords-type question requires all keywords to be matched in 	 * the user's answer for it to be considered correct and awarded any score.	 * If this is true, no score should be awarded if any of the keywords is not found in the user's answer.	 * If this is false, a partial score may be awarded (subject to other business rules) if some keywords is found in the user's answer.	 * This property is only relevent for a keywords-type question and ignored for other types.	 *	 * @ejb.interface-method	 *	 * @param match true if all keywords are required to be matched, otherwise false.	 */	public abstract void setMustMatchAllKeywords(boolean match);	    /**     * Checks if this question is active. An active question     * may be allocated to a test, editted and used.     * An inactive question may be considered to be logically removed     * from the system, but is kept in the database to maintain      * consistency in reporting and historical logging.     *     * @ejb.interface-method     *     * @return true if this question is active, false if inactive.     */    public boolean isAssignedToTest()    {        return getAssignedToTest();    }    	/**	 * Checks if this question is active. An active question	 * may be allocated to a test, editted and used.	 * An inactive question may be considered to be logically removed	 * from the system, but is kept in the database to maintain 	 * consistency in reporting and historical logging.	 *	 * @ejb.interface-method	 *	 * @return true if this question is active, false if inactive.	 */	public boolean isActive()	{		return getActive();	}	/**	 * Gets whether a keywords-type question requires all keywords to be matched in 	 * the user's answer for it to be considered correct and awarded any score.	 * If this is true, no score should be awarded if any of the keywords is not found in the user's answer.	 * If this is false, a partial score may be awarded (subject to other business rules) if some keywords is found in the user's answer.	 * This property is only relevent for a keywords-type question and ignored for other types.	 *	 * @ejb.interface-method	 *	 * @return true if all keywords are required to be matched, otherwise false.	 */	public boolean isMustMatchAllKeywords()	{		return getMustMatchAllKeywords();	}	/**	 * Actives this question, so that it may be editted and used.	 * This method may perform some checks first to ensure that this question	 * can be safely activated.	 *	 * @ejb.interface-method	 *	 * @return true if this question is activated, false if it is not (either a problem or it is already active)	 */	public boolean activate()	{		// Can always activate as long as it is currently inactive.		if (!isActive())		{			setActive(true);			return true;		}		return false;	}	/**	 * Deactives this question, after which it may be considered to be logically removed	 * from the system.	 * This method may perform some checks first to ensure that this question	 * can be safely deactivated.	 *	 * @ejb.interface-method	 *	 * @return true if this question is deactivated, false if it is not (either a problem or it is already inactive)	 */	public boolean deactivate()	{		// Can only deactivate if it is currently active and not assigned to any Test.		if (isActive() && (getTest()==null) )		{			setActive(false);			return true;		}		return false;	}	/**	* Gets the answer choices as array of LocalAnswerChoice instances. 	* The answer refers to the index to this array.	 *	 * @ejb.interface-method	 *	* @return Array of answer choices.	*/	public LocalAnswerChoice[] getAnswerChoices()	{		Set answerChoiceSet = getAnswerChoiceSet();		LocalAnswerChoice[] answerChoiceArr = new LocalAnswerChoice[ answerChoiceSet.size()];		for (int c=0; c<answerChoiceArr.length; c++)		{	// initalize all elements to null for safety.			answerChoiceArr[c] = null;		}		Iterator answerChoiceIter = answerChoiceSet.iterator();		while (answerChoiceIter.hasNext())		{			LocalAnswerChoice choice = (LocalAnswerChoice)answerChoiceIter.next();			int index = choice.getAnswerIndex();			if (index < answerChoiceArr.length)			{				answerChoiceArr[ index ] = choice;			}		}		return answerChoiceArr;	}	/**	* Adds an answer choice. 	 *	 * @ejb.interface-method	 *	* @param choice Answer choice to add.	*/	public void addAnswerChoice(LocalAnswerChoice choice)	{		if (isActive())		{			Set answerChoiceSet = getAnswerChoiceSet();			answerChoiceSet.add(choice);		}	}		/**	* Sets the text of an existing answer choice.	*	* @ejb.interface-method	*	* @param index  Index of answer choice to set.	* @param text  Text to set.	* @return true if the answer choice exists and is set, otherwise false.	*/	public boolean setAnswerChoiceText(int index, String text)	{		boolean success = false;		if (isActive())		{			Set answerChoiceSet = getAnswerChoiceSet();			// Find the answer choice with the specified index.			Iterator choiceIter = answerChoiceSet.iterator();			while (choiceIter.hasNext())			{				LocalAnswerChoice choice = (LocalAnswerChoice)choiceIter.next();				if (choice.getAnswerIndex()==index)				{					success = true;					choice.setAnswerText(text);					break;				}			}					}				return success;	}	/**	* <p>	* Checks the specified response to determine if it	* matches the answer for this Question. The response 	* parameter and returced value differ for different question types.	* </p><ul>	* <li>	* For a single-choice question, response parameter is the String 	* representation of the index to a answer shoice, e.g. "2". 	* The returned value is either 1.0 for correct response or 0.0 for incorrect response. 	* </li><li>	* For a multiple-choice question, it is a comma-separated list of	* indices that refers to multiple answer choices, e.g. "0,1,3"	* The returned value is either 1.0 for ALL correct responses or 0.0 for ANY incorrect response. 	* This means the user must select all the correct choices to be counted as correct.	* </li><li>	* For a keywords question, it is the text that is entered by the user.	* If the mustMatchAllKeywords property is false, the returned value is a value 	* between 0.0 and 1.0 that indicates the proportion of answer keywords that appear 	* in the response text. If none of the keywords appear, it returns 0.0. If all the 	* keywords appear, it returns 1.0. This comparison is not case sensitive.	* If the mustMatchAllKeywords property is true, the returned value is either 1.0 if	* ALL the keywords are found in the response text or 0.0 if ANY keyword is not found	* in the response text.	* </li>	* 	* @ejb.interface-method	*	* @param response  The response to check.	* @return A value between 0.0 and 1.0.	*/	public double checkResponse( String response)	{		Integer type = getType();		double retVal = 0.0;		if ( IQuestionType.SINGLE_CHOICE_TYPE.equals(type) )		{			int responseIdx = Integer.parseInt(response);			int answerIdx = Integer.parseInt(getAnswer());			retVal = (responseIdx==answerIdx) ? 1.0 : 0.0;		}		else if ( IQuestionType.MULTIPLE_CHOICE_TYPE.equals(type) )		{			String[] answerIndices = getAnswer().split(",");			String[] responseIndices = response.split(",");			// If different lengths, then its a mismatch			if (answerIndices.length==responseIndices.length)			{				// Sort both arrays, then compare them				Arrays.sort(answerIndices);				Arrays.sort(responseIndices);				retVal = Arrays.equals(answerIndices, responseIndices) ? 1.0 : 0.0;			}		}		else if ( IQuestionType.KEYWORDS_TYPE.equals(type))		{			// Make response lower-case to avoid case problems			String responseLower = response.toLowerCase(); 			String[] keywords = getAnswer().split(",");			if (keywords.length>0)			{				if (isMustMatchAllKeywords())				{					retVal = 1.0;					for (int k=0; k<keywords.length; k++)					{						if (responseLower.indexOf(keywords[k])==-1)						{							retVal = 0.0;							break;						}					}				}				else				{					double perMatchIncrement = 1.0/keywords.length;					for (int k=0; k<keywords.length; k++)					{						if (responseLower.indexOf(keywords[k])>=0)						{							retVal += perMatchIncrement;						}					}				}			}		}				return retVal;	}	/**	* Sets the difficulty of this Question.	 *	 * @ejb.interface-method	 *	* @param diff Difficulty of this Question.	*/	public void setDifficulty( DifficultyEnum diff)	{		setDifficultyCode(diff.getCode());	}	/**	* Gets the difficulty of this Question.	 *	 * @ejb.interface-method	 *	* @return Difficulty of this Question.	*/	public DifficultyEnum getDifficulty()	{		return DifficultyEnum.getEnumFromCode(getDifficultyCode());	}	//-----------------------------	// Create methods.	//-----------------------------	/**	* Creates an Question.	*	* @ejb.create-method view-type="local"	*/	public Integer ejbCreate( String name, String ques, String answer,		String hint, DifficultyEnum difficulty,		String explain, Integer type, int timeLimitSecs, int score,		boolean active, boolean mustMatchAllKeywords) throws CreateException	{        // Note : Unique ID is assigned by database auto-increment		setName(name);		setContent(ques);		setAnswer(answer);		setHint(hint);		setType(type);		setDifficultyCode(difficulty.getCode());		setScore(score);		setExplanation( explain);		setTimeLimitSeconds(timeLimitSecs);		setActive(active);        setAssignedToTest( false );        setMustMatchAllKeywords(mustMatchAllKeywords);		long nowMillis = System.currentTimeMillis();		setCreatedMillis( nowMillis );		setLastModifiedMillis(nowMillis);		return null;	}		public void ejbPostCreate( String name, String ques, String answer,		String hint, DifficultyEnum difficulty,		String explain, Integer type, int timeLimitSecs, int score, 		boolean active, boolean mustMatchAllKeywords  )	{        // Not used	}		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -