package questions; import java.util.Collection; import tests.Test; /** * A Question Bank stores all questions that have been created and includes * functionalites to add, remove, find, or sort questions. */ public abstract class QuestionBank { int numQuestions; Collection questions; /** * Adds a new question into the question bank. * @param question The question to be added to the question bank. pre: // There is no record in the Collection that is exactly the same as // the question to be added. // !exists (Question quest ; questions.contains(quest) ; quest.questionText.equals(question.questionText) && quest.answer.equals(question.answer)) && // The question is not empty. (question.questionText != null) && (question.questionText.length() > 0) && // The answer is not empty. (question.answer != null) && (question.answer.length() > 0) && // The time and difficulty are not empty. (question.time != 0) && (question.difficulty != 0) post: // A record is in the output data if and only if it is the // new record to be added or if it is in the input data. // forall (Question quest ; questions'.contains(quest) iff quest.questionText.equals(question.questionText) && quest.answer.equals(question.answer) || questions.contains(quest)); */ void addQuestion(Question question) { boolean b = (question.answer != null) && (question.answer.length() > 0); } /* SPEST PROBLEM: There were some probems in this file that the checker correctly identified, but the following two remaining errors don't seem to be correct since javac is OK with the expressions on line 32: Invalid invocation: length() at line: 32 at character: 49 Expected type: null, but found: int at line: 32 character: 59 */ /** * Deletes a question from the question bank. * @param question The question to be removed from the question bank. pre: // The given question is in this.questions. // questions.contains(question); post: // A record is in the output data if and only if it is not the // existing record to be deleted and it is in the input data. // forall (Question quest ; questions'.contains(quest) iff !quest.questionText.equals(question.questionText) && !quest.answer.equals(question.answer) && questions.contains(quest)); */ abstract void deleteQuestion(Question question); /** * Finds a question in the question bank. * @param question The target question to search for in the bank. post: // If the target question exists in the question bank, then the output // is equal to that question, otherwise output is null. // exists (Question quest ; questions.contains(quest) ; quest.questionText.equals(question.questionText) && quest.answer.equals(question.answer) && quest.equals(return)) || !exists (Question quest ; questions.contains(quest) ; quest.questionText.equals(question.questionText) && quest.answer.equals(question.answer)) && return == null; */ abstract void findQuestion(Question question); /** * Sorts all questions on a user-selected condition. */ abstract void sortQuestions(); }