q.java

来自「codebook!」· Java 代码 · 共 85 行

JAVA
85
字号
/** * A Q is one Question used in TestEdit. */public class Q extends java.util.Observable {	public static final String labels[] = {			"A", "B", "C", "D"	};	/** The text of the question */	String   question;	/** The text of the alternative answers. */	String[] ans;	/** The number of the answer that is correct. Zero-based. */	int      correct;	/** The number of the chapter that this question relates to */	int	objective;	/** A Boolean for use by Interactive Programs */	boolean tried = false;	public String toString() {		return "Q[" + question + "]";	}	/** construct a Q given the # of answers allowed. */	Q(int n) {		if (n<0 || n>10)			throw new IllegalArgumentException("Q.init: Count " + n + " invalid");		question = "";		ans = new String[n];		correct = objective = -1;	}	/** Get the number of questions.	 * @deprecated See getNumAnswers.	 */	public int getCount() {		return getNumAnswers();	}	/** Get the number of questions. */	public int getNumAnswers() {		return ans.length;	}	public int getAns() {		return correct;	}	public void setAns(int i, boolean notify) {		if (i<0 || i>=getCount())			throw new IllegalArgumentException("Q.setAns: Count " + i + " invalid");		correct = i;		setChanged();		// if (notify)		// 	notifyObservers(new QChangeEvent(this,		// 		QChangeEvent.CHANGE_ANSWER_NUMBER, i, null));	}	void setQText(String s, boolean notify) {		question = s;		setChanged();		// if (notify)		// 	notifyObservers(new QChangeEvent(this,		// 		QChangeEvent.CHANGE_QUESTION_TEXT, -1, s));	}	String getQText() {		return question;	}	void setAnsText(int i, String s, boolean notify) {		if (i<0 || i>=getCount())			throw new IllegalArgumentException("Q.setAnsText: Count " + i + " invalid");		ans[i] = s;		setChanged();		// if (notify)		// 	notifyObservers(new QChangeEvent(this,		// 		QChangeEvent.CHANGE_ANSWER_TEXT, i, s));	}	String getAnsText(int i) {		return ans[i];	}	void setObjective(int i) {		objective = i;	}	int getObjective() {		return objective;	}}

⌨️ 快捷键说明

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