Assignment 5: Using Java built-in Lists
Goals: Practice using Java’s existing classes to implement various list operations.
1 Questions in a questionnaire
Many online questionnaire tools like SurveyMonkey, Doodle Poll, etc. (even Blackboard) allow creating a questionnaire made of several types of questions: Yes/No, Short-answer, Likert scale, etc. In this assignment, you will write classes that represent different types of questions, and a class to represent a questionnaire.
Each question, irrespective of type, has the following common aspects:
It has the text of the question itself, and a method getPrompt that returns it.
It is either required or optional, and has a method isRequired that returns its status.
It has a method answer(String) that allows one to enter an answer as a String. What the string may contain depends on the type of question.
It has a method getAnswer that returns the answer to the question, or empty string if there is no answer.
It has a method copy that returns a copy of the question including all its data.
The types of questions are:
YesNo: this can be answered in one of two ways: yes or no. answer(String) would accept "Yes" or "No" as valid answers, but case-insensitive, so "yes" or "NO" would also be valid.
ShortAnswer: this can be answered in at most 280 characters, including spaces.
Likert: this can be answered on a fixed, 5-point Likert scale (Strongly Agree, Agree, Neither Agree nor Disagree, Disagree, Strongly Disagree). answer(String) would accept only these precise words as valid answers, but again case-insensitive.
All code for this assignment should be in the cs5004.questionnaire package.
Design an interface Question to represent a question, with the methods listed. Then design the implementing classes YesNo, ShortAnswer, and Likert. Each of those classes should have a constructor that takes in the question prompt as a String and a boolean where true means the question is required, and false means optional. The answer() method in each of these classes will enforce the answer requirements for that question type. Consider using the equalsIgnoreCase() method on the String class to check for case-insensitive String equality. We have supplied you with an enum definition representing the Likert response options. (Not all aspects of this enum are relevant for this assignment.) Note that you can get the values of an enum as an array using the static values() method on the class, such as LikertResponseOption.values().
We have supplied you with an interface Questionnaire, representing a collection of questions. Implement this interface in a class called QuestionnaireImpl, that has only a no-argument constructor. Within this QuestionnaireImpl class, you must make use of Java’s built-in List<T> interface and a built-in implementaiton of List<T>.
Write tests for both the Question and the Questionnaire interface, to ensure that they work correctly in a range of situations. Do not modify any of the given code (except for style fixes should they be necessary).
How to submit
Create a zip file that contains directly your src and test folders. When you unzip the file, you should see only these two folders.
Log on to the Bottlenose submission server.
Navigate to Assignment 5 and submit the zip file.
Wait for a few minutes for feedback to appear, and take action if needed.