Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me implement this in java x package cs5004.questionnaire; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; import java.util.function.BiFunction; import java.util.function.Predicate; /** * Represents a collection

Please help me implement this in java

image text in transcribedimage text in transcribedx

package cs5004.questionnaire; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; import java.util.function.BiFunction; import java.util.function.Predicate; /** * Represents a collection of {@link Question}s, forming a questionnaire. */ public interface Questionnaire { /** * Add a question to the questionnaire. * * @param identifier a name for the question unique within this questionnaire. Not null * or empty. * @param q the {@link Question} to be added to the questionnaire */ void addQuestion(String identifier, Question q); /** * Remove the question with the given identifier from the questionnaire. * * @param identifier the identifier of the question to be removed. * @throws NoSuchElementException if there is no question with the given identifier. */ void removeQuestion(String identifier); /** * Get the question with the given number, based on the order in which it was added to the * questionnaire, or the sorted order if the {@code sort()} method is called. The first question * is 1, second 2, etc. * * @param num the number of the question, counting from 1 * @return the question * @throws IndexOutOfBoundsException if there is no such question num */ Question getQuestion(int num); /** * Get the question with the given identifier (question having been previously added to the * questionnaire). * * @param identifier the identifier of the question * @return the question * @throws NoSuchElementException if there is no question with the identifier */ Question getQuestion(String identifier); /** * Return a list of all required questions in the questionnaire. * * @return the required questions. */ List getRequiredQuestions(); /** * Return a list of all optional questions in the questionnaire. * * @return the optional questions. */ List getOptionalQuestions(); /** * Report if all required questions have some non-empty response. * * @return true if all required questions have responses, false otherwise. */ boolean isComplete(); /** * Return a list of just the responses to all the questions in the questionnaire. * * @return the responses */ List getResponses(); /** * Produce a new questionnaire containing just the questions where the given predicate returns * true. The returned questionnaire is completely independent of this questionnaire. That is, * the questions in the returned questionnaire are copies of the original questions. * * @param pq the predicate * @return the new questionnaire */ Questionnaire filter(Predicate pq); /** * Sort the questions according to the given comparator. Return values from * {@code getQuestion(int)} should reflect the new sorted order following sort. * * @param comp a comparator for Question */ void sort(Comparator comp); /** * Produce a single summary value based on the given folding function and * seed value. * * @param bf the folding function * @param seed the seed value * @param  the return type * @return the summary value */  R fold(BiFunction bf, R seed); /** * Convert the questionnaire into a single string in the format of * Question: [prompt] then two newlines * Answer: [answer] two newlines, and so on. Example result for a questionnaire with 3 questions: * Question: What is your name? * * 

Answer: Sir Lancelot * *

Question: What is your quest? * *

Answer: I seek the Holy Grail. * *

Question: What is your favorite color? * *

Answer: Blue. * * @return the questionnaire as a String */ String toString(); }

Assignment 4: Questions in a questionnaire . . Questions in a questionnaire Many online questionnaire tools like SurveyMonkey, Doodle Poll, etc. (even Blackboardy 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 retumsit, it is either required or optional, and has a method is required 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 retums a copy of the question including all its data. The types of questions are: 1. YenNo this can be answered in one of two ways: yes or no answer (string) would accept "Yes" or "No" is valid answers, but case-insensitive, so "yes" or "No would also be valid 2. shortAnaver: this can be answered in at most 280 characters, including spaces, 3. Likert: this can be answered on a fixed, 5-point Likert scalo (Strongly Agree, Agree, Nolther Agree nor Disagree. Disagree, Strongly Disagree) answer (string) would accept only those precise words as valid answers, but again case-insensitive. All code for this assignment should be in the ca5004.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 talse means optional. The answer method in each of these classes will enforce the answer requirements for that question type. Consider using the equalIgnorecase () 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 Questionnaire Imp1, that has only a no-argument constructor. Within this questionnaire Impl class, you must make use of Java's built-in List interface and a built-in implementation of List. 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). package cs5004.questionnaire; enum LikertResponseOption { STRONGLY_DISAGREE(-2, "Strongly Disagree"), DISAGREE(-1, "Disagree"), NEUTRAL(O, "Neither Agree Nor Disagree"), AGREE(1, "Agree"), STRONGLY_AGREE(2, "Strongly Agree"); private final int val; private final String txt; LikertResponseOption(int val, String txt) { this.val = val; this.txt = txt; } int getValue() { return val; } String getText() { return txt; } 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions