public class Question implements Comparable, Serializable {
public static final int BOOLEAN = 1;
public static final int MULTICHOICE = 2;
public static final int MULTIANSWER = 3;
private int type; // "BO", "MC" or "MA"
private String question;
private Answer[] answers;
public Question(int type, String question, Answer[] answers) {
this.type = type;
this.question = question;
this.answers = answers;
}
public int getType() { return type; }
public boolean isBoolean() { return type == BOOLEAN; }
public boolean isMultiChoice() { return type == MULTICHOICE; }
public boolean isMultiAnswer() { return type == MULTIANSWER; }
public String getQuestion() { return question; }
public Answer[] getAnswers() { return answers; }
public Answer getAnswer() { return answers[0]; }
public Question makeCopy() {
Answer[] cheats = new Answer[answers.length];
for (int i = 0; i < answers.length; i++) {
cheats[i] = answers[i].makeCopy();
}
return new Question(type, question, cheats);
}
}
|
|
public class Answer implements java.io.Serializable {
private static final int DONT_KNOW = -1;
private static final int NO = 0;
private static final int YES = 1;
private String code;
private String name;
private int answer = DONT_KNOW;
public Answer(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() { return code; }
public String getName() { return name; }
public boolean isAnswered() { return answer != DONT_KNOW; }
public boolean isYes() { return answer == YES; }
public void setYes(boolean yes) { answer = yes ? YES : NO; }
public void setDontKnow() { answer = DONT_KNOW; }
public Answer makeCopy() {
Answer copy = new Answer(code, name);
if (isAnswered()) {
copy.setYes(isYes());
}
return copy;
}
}
|
|