Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Assignment Questions in a questionnaire Many online questionnaire tools like SurveyMonkey, Doodle Poll, etc. (even Blackboard) allow creating a questionnaire made of several types

JAVA Assignment

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:

  1. 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.

  2. ShortAnswer: this can be answered in at most 280 characters, including spaces.

  3. 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 Stringclass 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.)

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 Javas built-in List interface and a built-in implementaiton of List.

Write tests for both the Question and the Questionnaire interface, to ensure that they work correctly in a range of situations.

//LikertResponseOption.java

enum LikertResponseOption { STRONGLY_DISAGREE(-2, "Strongly Disagree"), DISAGREE(-1, "Disagree"), NEUTRAL(0, "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; } }

//Questionnaire.java

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. The first question added would be 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. * * @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(); }

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

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

Is this a violation of the EPA?

Answered: 1 week ago

Question

8 . What should be the first step to fixing any business process?

Answered: 1 week ago

Question

=+designing international assignment C&B packages.

Answered: 1 week ago