@SuppressWarnings("unchecked")
  //we are feeding in the proper type so casting should not be an issue
  @Override
  public void process(JCas aJCas) throws AnalysisEngineProcessException {
    
    // STEP 1: sort the answers by score
    Iterator<AnswerScore> answerScoreIter = 
            (Iterator<AnswerScore>) getAnnotationsFromIndex(aJCas, AnswerScore.type);
    List<AnswerScore> answerScoreList = new ArrayList<AnswerScore>();
    while (answerScoreIter.hasNext()) {
      answerScoreList.add(answerScoreIter.next());
    }
    // the following few lines to sort the AnswerScore by score are inspired by
    // http://stackoverflow.com/questions/5805602/how-to-sort-list-of-objects-by-some-property
    Collections.sort(answerScoreList, new Comparator<AnswerScore>() {
      public int compare(AnswerScore a1, AnswerScore a2) {
          return Double.compare(a2.getScore(), a1.getScore());
      }
    });
    
    // STEP 2: print test element
    // STEP 2.1: print question
    Iterator<Question> questionIter = (Iterator<Question>) getAnnotationsFromIndex(aJCas,
            Question.type);
    // there should only be one question
    if (questionIter.hasNext()) {
      Question question = (Question)questionIter.next();
      System.out.println(String.format("Question: %s", question.getCoveredText()));
    } else {
      throw new AnalysisEngineProcessException();
    }
    // STEP 2.2:  print the answers.  Count the correct ones while we're at it.
    int len = answerScoreList.size();
    int N = 0;
    for (int i = 0; i < len; i ++) {
      AnswerScore answerScore = answerScoreList.get(i);
      boolean correct = false;
      if (answerScore.getAnswer().getIsCorrect()) {
        correct = true;
        N ++;
      }
      System.out.println(String.format("%s %1.2f %s",
              correct ? "+" : "-",
              answerScore.getScore(),
              answerScore.getCoveredText()));
    }
    // no answers to evaluate
    if (N == 0) {
      throw new AnalysisEngineProcessException();
    }
    
    // STEP 3: compute and print precision
    int correctAtN = 0;
    for (int i = 0; i < N; i ++) {
      AnswerScore answerScore = answerScoreList.get(i);
      if (answerScore.getAnswer().getIsCorrect()) {
        correctAtN ++;
      }
    }
    System.out.println(String.format("Precision at %d: %1.2f", N, ((double)correctAtN/N)));
  }