From e931adb3c50e55e5b6af89d411bf9a7be950f69a Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Tue, 17 Sep 2013 22:28:51 -0700 Subject: 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. --- src/com/p4square/grow/model/Answer.java | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/com/p4square/grow/model/Answer.java (limited to 'src/com/p4square/grow/model/Answer.java') 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 + */ +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 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; + } +} -- cgit v1.2.3