summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/model/Answer.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-09-17 22:28:51 -0700
committerJesse Morgan <jesse@jesterpm.net>2013-09-17 22:28:51 -0700
commite931adb3c50e55e5b6af89d411bf9a7be950f69a (patch)
tree57774a79de369ef6963b52cdb074f534c4b4a926 /src/com/p4square/grow/model/Answer.java
parent45202b50ece500430d9e560208b08a8283f76b96 (diff)
Fixing question 4 to skip 4a in some cases.
For this fix I am moving Question and Answer from the backend into a new model package. Question is now used in SurveyPageResource instead of the Map. Eventually I should encode/decode the model from the json directly. I am adding support to the Question model to find the next question based on the answer to the current question. If the answer has a specific nextQuestion field, that is used. Otherwise the question's nextQuestion field is used. This is to facilitate skipping irrelevant questions.
Diffstat (limited to 'src/com/p4square/grow/model/Answer.java')
-rw-r--r--src/com/p4square/grow/model/Answer.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/com/p4square/grow/model/Answer.java b/src/com/p4square/grow/model/Answer.java
new file mode 100644
index 0000000..4c84060
--- /dev/null
+++ b/src/com/p4square/grow/model/Answer.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import java.util.Map;
+
+/**
+ * This is the model of an assessment question's answer.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class Answer {
+ public static enum ScoreType {
+ NONE, AVERAGE, TRUMP;
+ }
+
+ private final String mAnswerId;
+ private final String mAnswerText;
+ private final ScoreType mType;
+ private final float mScoreFactor;
+ private final String mNextQuestionId;
+
+ public Answer(final String id, final Map<String, Object> answer) {
+ mAnswerId = id;
+ mAnswerText = (String) answer.get("text");
+ final String typeStr = (String) answer.get("type");
+ if (typeStr == null) {
+ mType = ScoreType.AVERAGE;
+ } else {
+ mType = ScoreType.valueOf(typeStr.toUpperCase());
+ }
+
+ if (mType != ScoreType.NONE) {
+ mScoreFactor = Float.valueOf((String) answer.get("score"));
+ } else {
+ mScoreFactor = 0;
+ }
+
+ mNextQuestionId = (String) answer.get("nextQuestion");
+ }
+
+ public String getId() {
+ return mAnswerId;
+ }
+
+ public String getText() {
+ return mAnswerText;
+ }
+
+ public ScoreType getType() {
+ return mType;
+ }
+
+ public float getScoreFactor() {
+ return mScoreFactor;
+ }
+
+ public String getNextQuestion() {
+ return mNextQuestionId;
+ }
+}