コード例 #1
0
  private void createResponse(Contact c, Assessment a, int questionNumber, boolean correct) {
    AssessmentMessage am = null;
    for (AssessmentMessage m : a.getMessages()) {
      if (m.getTopicItem() instanceof Question) {
        if (--questionNumber < 0) {
          am = m;
          break;
        }
      }
    }
    if (am == null) throw new RuntimeException("Could not find question #" + questionNumber);

    Question q = (Question) am.getTopicItem();
    int answer = correct ? q.getCorrectAnswer() : q.getCorrectAnswer() + 1 % q.getAnswers().length;
    AssessmentMessageResponse r = new AssessmentMessageResponse();
    r.setStudent(c);
    r.setAnswer(answer);
    r.setAssessmentMessage(am);
    r.setCorrect(correct);
    assessmentMessageResponseDao.save(r);
  }
コード例 #2
0
  private Assessment createAssessment(Group g, int questionCount, int reinforcementCount) {
    Assessment a = new Assessment();
    a.setGroup(g);

    List<AssessmentMessage> messages = new ArrayList<AssessmentMessage>();
    for (int i = 0; i < Math.max(questionCount, reinforcementCount); ++i) {
      if (i < questionCount) {
        Question q = new Question();
        q.setAnswers(new String[3]);
        questionDao.save(q);
        messages.add(new AssessmentMessage(q));
      }
      if (i < reinforcementCount) {
        Reinforcement r = new Reinforcement();
        reinforcementDao.save(r);
        messages.add(new AssessmentMessage(r));
      }
    }
    a.setMessages(messages);

    assessmentDao.save(a);

    return a;
  }