public static List<Question> generateQuestionSet(int difficulty, int questionSetSize) { List<Question> questionList = new ArrayList<>(questionSetSize); for (int i = 0; i < questionSetSize; ++i) { try { Question q = generateQuestion(difficulty, 4 * questionSetSize, true); q.question = q.getQuestion().replaceAll("\\s\\s", " "); q.question = q.getQuestion().replaceAll("\\(\\s", "("); q.question = q.getQuestion().replaceAll("\\s\\)", ")"); q.question = q.getQuestion().replaceAll("\\s\\?", "?"); q.question = q.getQuestion().replaceAll("\\s\\.", "."); for (int j = 0; j < q.getChoices().size(); ++j) { q.getChoices().set(j, q.getChoices().get(j).trim()); } questionList.add(q); } catch (SQLException e) { e.printStackTrace(); } } return questionList; }
public void save() { try { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); Date date = new Date(); String fileName = getName() + ".txt"; PrintWriter write; write = new PrintWriter(fileName); // Template write.println("Questionnaire\t" + getName()); write.println("Date\t" + dateFormat.format(date)); write.println("NumTestSubjects\t" + getAnswerSets().size()); write.print("ID\t"); List<Question> questions = getQuestions(); // Different ways of storing different types of question e.g. // MultipleChoice - Good?[MultipleChoiceQuestion(No,OK,Good,Best)]\t // ScaleQuestion - How Good?[ScaleQuestion,5]\t // OpenQuestion - Name?[OpenQuestion]\t for (Question q : questions) { if (q.getType() == QuestionType.MultipleChoiceQuestion) { write.print(q.getDescription() + "[" + q.getType() + "("); for (int i = 0; i < q.getChoices().size(); i++) { if (i == (q.getChoices().size() - 1)) { write.print(q.getChoices().get(i) + ")"); continue; } write.print(q.getChoices().get(i) + ","); } write.print("]" + "\t"); } else if (q.getType() == QuestionType.ScaleQuestion) { write.print(q.getDescription() + "[" + q.getType()); write.print("," + q.getInterval()); write.print("]" + "\t"); } else { write.print(q.getDescription() + "[" + q.getType() + "]" + "\t"); } } write.println(); // AnswerSets List<AnswerSet> answerSets = getAnswerSets(); List<Answer> answers; for (AnswerSet set : answerSets) { answers = set.getAnswers(); write.print(set.getTestSubjectID() + "\t"); for (int i = 0; i < answers.size(); i++) { // if question is timed then format is e.g. answer[5] if (questions.get(i).isTimed() == true) { write.print( answers.get(i).toString() + "[" + answers.get(i).getDuration() + "]" + "\t"); } else { write.print(answers.get(i).toString() + "\t"); } } write.println(); } write.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }