001: package org.sakaiproject.tool.assessment.samlite.api;
002:
003: import java.util.LinkedList;
004: import java.util.List;
005: import java.util.Iterator;
006:
007: public class Question {
008: public static final int UNDEFINED_QUESTION = 0;
009: public static final int MULTIPLE_CHOICE_QUESTION = 10;
010: public static final int MULTIPLE_CHOICE_MULTIPLE_ANSWER_QUESTION = 15;
011: public static final int FILL_IN_THE_BLANK_QUESTION = 20;
012: public static final int TRUE_FALSE_QUESTION = 30;
013: public static final int SHORT_ESSAY_QUESTION = 40;
014:
015: private int questionNumber;
016: private String questionPoints;
017: private List questionLines;
018: private int questionType;
019: private String correctAnswer;
020: private List answers;
021: private boolean hasPoints;
022:
023: public Question() {
024: this .questionNumber = 0;
025: this .questionPoints = "";
026: this .questionLines = new LinkedList();
027: this .questionType = UNDEFINED_QUESTION;
028: this .correctAnswer = "";
029: this .answers = new LinkedList();
030: this .hasPoints = false;
031: }
032:
033: public void addAnswer(String id, String text, boolean isCorrect) {
034: this .answers.add(new Answer(id, text, isCorrect));
035: }
036:
037: public List getAnswers() {
038: return answers;
039: }
040:
041: public void setAnswers(List answers) {
042: this .answers = answers;
043: }
044:
045: public String getCorrectAnswer() {
046: return correctAnswer;
047: }
048:
049: public void setCorrectAnswer(String correctAnswer) {
050: this .correctAnswer = correctAnswer;
051: }
052:
053: public String getQuestion() {
054: StringBuffer buffer = new StringBuffer();
055:
056: for (Iterator it = questionLines.iterator(); it.hasNext();) {
057: String line = (String) it.next();
058: if (null != line && !"".equals(line))
059: buffer.append(line.trim()).append(" ");
060: }
061:
062: return buffer.toString();
063: }
064:
065: public void append(String questionSegment) {
066: this .questionLines.add(questionSegment);
067: }
068:
069: public int getQuestionNumber() {
070: return questionNumber;
071: }
072:
073: public void setQuestionNumber(int questionNumber) {
074: this .questionNumber = questionNumber;
075: }
076:
077: public String getQuestionPoints() {
078: return questionPoints;
079: }
080:
081: public void setQuestionPoints(String questionPoints) {
082: if (null != questionPoints && !"".equals(questionPoints))
083: this .hasPoints = true;
084: this .questionPoints = questionPoints;
085: }
086:
087: public boolean hasPoints() {
088: return hasPoints;
089: }
090:
091: public String getQuestionTypeAsString() {
092: switch (questionType) {
093: case MULTIPLE_CHOICE_QUESTION:
094: return "Multiple Choice";
095: case MULTIPLE_CHOICE_MULTIPLE_ANSWER_QUESTION:
096: return "Multiple Correct Choices";
097: case FILL_IN_THE_BLANK_QUESTION:
098: return "Fill in the Blank";
099: case TRUE_FALSE_QUESTION:
100: return "True/False";
101: case SHORT_ESSAY_QUESTION:
102: return "Short Essay";
103: }
104: ;
105: return "Unrecognized Type";
106: }
107:
108: public int getQuestionType() {
109: return questionType;
110: }
111:
112: public void setQuestionType(int questionType) {
113: this.questionType = questionType;
114: }
115:
116: }
|