@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Answer answer = (Answer) o; return getAnswerText().equals(answer.getAnswerText()); }
public static void unaswerAllQuestions(ArrayList<Question> list) { for (Question question : list) { for (Answer answer : question.answers) { if (answer.isSelected()) { answer.select(); } } } }
@Override public void writeHTML(DisplayContext dc) { for (int i = 0; i < stringList.size() - 1; ++i) { dc.append(stringList.get(i)); if (dc.isDisplayResponses()) { String[] answer = {"Your answer here"}; if (dc.getStudentResponses() != null) { answer = dc.getStudentResponses().getLatestResponse(getId()); } dc.append("<input type='text' disabled value='"); dc.append(answer[0]); dc.append("'> "); if (dc.isDisplayAnswers()) { Response res = getResponseFor(answer[0]); if (res != null) { if (Score.correctQues(getId(), answer) == getPoints()) { dc.append("<span class='response correct'>"); } else { dc.append("<span class='response'>"); } writeHTML(dc); dc.append("</span>"); } boolean hasAnswer = false; for (Answer ans : getAns()) { if (ans.getCorrect()) { hasAnswer = true; break; } } if (hasAnswer) { dc.append("\n<br>Possible answers:<br>"); for (Answer ans : getAns()) { ans.writeHTML(dc); dc.append("<br>"); } } } } else { // just show the empty box dc.append("<input name='").append(getId()).append("' class='fillin' type='text' />"); } } dc.append(stringList.get(stringList.size() - 1)); }
private void validateAnswerFields(CreateQuestion createQuestion, Errors errors) { Question question = createQuestion.getQuestion(); if (question.getAnswers().size() != createQuestion.getNumCorrect() + createQuestion.getNumIncorrect()) errors.rejectValue("", "invalid.answers", "all answers are mandatory"); for (Answer answer : question.getAnswers()) { if (!answer.isValid()) { errors.rejectValue( "", "invalid.answers", "all answers and their hints are mandatory and cannot be left blank"); return; } } }
/** * Returns the winner of this game. * * @return the winner of this game or <code>null</code> if there is no winner. */ public Player getWinner() { Player winner = null; Round lastRound = this.getLastRound(); if (lastRound == null) { return winner; } int correct = GameConfiguration.numberLength(); for (Player player : lastRound.getAnswers().keySet()) { Answer answer = lastRound.getAnswers().get(player); if (answer.getCorrect() == correct) { winner = player; break; } } return winner; }
public static boolean toCsv(String fullyNamedPath, Poll poll) { StringBuilder sb = new StringBuilder(); sb.append(String.format("Questions;Answer;Votes;WeightedVotes;%n")); for (Question question : poll.getQuestions()) { for (Answer answer : question.getAnswers()) { int votesCount = answer.getVotes().size(); int weightedVotesCount = answer.getVotes().size() * answer.getValue(); String questionTitle = question.getTitle().replace("\"", "\"\""); String answerText = answer.getText().replace("\"", "\"\""); sb.append( String.format( "\"%s\";\"%s\";%s;%s;%n", questionTitle, answerText, votesCount, weightedVotesCount)); } } return write(fullyNamedPath, sb.toString()); }
/** Handy constructor to build the ternary relationship */ public PatGivesAns2Ques(Question question, Answer answer, Patient patient) { this.question = question; this.answer = answer; this.patient = patient; // Assure bidirectional referential integrity question.getPatAnsQues().add(this); answer.getPatAnsQues().add(this); patient.getPatAnsQues().add(this); }
public static boolean deleteElement(ExamItemAbstract loadItem) { boolean ret = DaoExamAbstract.getDaoExam(selectedDao).deleteElement(loadItem); if (ret) { if (loadItem instanceof IQuestion) { Question.questionDeleted(loadItem); } else if (loadItem instanceof IAnswer) { Answer.answerDeleted((IAnswer) loadItem); } } return ret; }
public boolean matches(Criteria criteria) { score = 0; boolean kill = false; boolean anyMatches = false; for (Criterion criterion : criteria) { Answer answer = answers.get(criterion.getAnswer().getQuestionText()); boolean match = criterion.getWeight() == Weight.DontCare || answer.match(criterion.getAnswer()); if (!match && criterion.getWeight() == Weight.MustMatch) { kill = true; } if (match) { score += criterion.getWeight().getValue(); } anyMatches |= match; // ... } if (kill) return false; return anyMatches; }
public static Question nextQuestion(Boolean rotated) { if (rotated == true) { return lastSelected; } else { if (questionList.size() != 0) { Random r = new Random(); int randomIndex = r.nextInt(questionList.size()); Question selectedQuestion = questionList.get(randomIndex); lastSelected = selectedQuestion; for (Answer answer : selectedQuestion.answers) { if (answer.isSelected()) { answer.select(); } } return selectedQuestion; } else { return null; } } }
@Override protected T doInBackground(Void... params) { long startTime, endTime; T result = null; try { startTime = System.currentTimeMillis(); result = calculus.perform(); endTime = System.currentTimeMillis(); elapsedTime = endTime - startTime; return result; } catch (Exception e) { callback.ifFails(e); } return result; }
public static void reset() { ExamItemAbstract.highestMemberId = 1000; Question.reset(); Answer.reset(); }
@Override protected void onPostExecute(T t) { super.onPostExecute(t); if (t != null) callback.afterExecution(t, elapsedTime); }
@Test public void testPooling() { assertTrue(Answer.get("a") == Answer.get("a")); assertTrue(Answer.get("a") != Answer.get("b")); assertTrue(Answer.get("a") != Answer.get("aa")); }
public void setAnswer(Answer answer) { this.answer = answer; this.id_answer = (answer != null) ? answer.getId_answer() : null; }
private void load(File file) { try { Scanner in = new Scanner(file); // Template String line = in.nextLine(); name = line.split("\t")[1]; line = in.nextLine(); line = in.nextLine(); line = in.nextLine(); // Questions String[] lines = line.split("\t"); Question tmp; for (String s : lines) { // Skip first part of line if (s.equalsIgnoreCase("ID")) { continue; } String[] splitStringt = s.split("\\["); if (splitStringt[1].startsWith("MultipleChoiceQuestion")) { tmp = new Question(QuestionType.MultipleChoiceQuestion, splitStringt[0], false); for (String c : splitStringt[1].split("\\(")[1].split(",")) { if (c.contains(")]")) { tmp.addChoice(c.split("\\)]")[0]); continue; } tmp.addChoice(c); } addQuestion(tmp); } else if (splitStringt[1].startsWith("ScaleQuestion")) { tmp = new Question( QuestionType.ScaleQuestion, splitStringt[0], Integer.parseInt( splitStringt[1].substring( splitStringt[1].indexOf(",") + 1, splitStringt[1].length() - 1)), false); addQuestion(tmp); } else { tmp = new Question(QuestionType.OpenQuestion, splitStringt[0], false); addQuestion(tmp); } } // AnswerSets AnswerSet aSet = null; Answer tmpAns = null; while (in.hasNextLine()) { line = in.nextLine(); lines = line.split("\t"); aSet = new AnswerSet(lines[0]); for (int i = 0; i < getQuestions().size(); i++) { tmpAns = new Answer(getQuestions().get(i)); // setting question to a timed question and getting and setting time to answer if (lines[i + 1].contains("]")) { getQuestions().get(i).setIsTimed(true); String time = lines[i + 1].split("\\[")[1]; tmpAns.setChosenAnswer(lines[i + 1].split("\\[")[0]); time = time.substring(0, time.length() - 1); tmpAns.setDuration((long) Integer.parseInt(time)); } else { tmpAns.setChosenAnswer(lines[i + 1]); } aSet.addAnswer(tmpAns); } addAnswerSet(aSet); } in.close(); } catch (FileNotFoundException e) { System.out.println("No File called: " + file.getName()); } }
private void GetAnswers(Integer _id) { openDatabaseConnection(); String WhereStatement = "QUESTIONITEM " + "= " + String.valueOf(_id); String[] Columns = {"CORRECT", "ANSWERTEXT", "REASON"}; Cursor c = myDbHelper.query("ANSWERS", Columns, WhereStatement, null, null, null, null); if (c.getCount() > 0) { c.moveToFirst(); List<Answer> list = new ArrayList<Answer>(); CorrectAnswerList = new ArrayList<Answer>(); CorrectAnswerInHTMLList = new ArrayList<String>(); do { Answer ans = new Answer(); ans.set_Correct(c.getInt(c.getColumnIndex("CORRECT"))); ans.set_AnswerText(c.getString(c.getColumnIndex("ANSWERTEXT"))); ans.set_Reason(c.getString(c.getColumnIndex("REASON"))); list.add(ans); // if the answer is correct keep the string in HTML if (ans.get_Correct() == 1) { String CorrectAnswerInHTML = ans.get_AnswerText(); CorrectAnswerReasonInHTML = ans.get_Reason(); CorrectAnswerList.add(ans); // Collection of correct answers CorrectAnswerInHTMLList.add(CorrectAnswerInHTML); CorrectAnswerInHTMLListCounter++; } } while (c.moveToNext()); c.close(); myDbHelper.close(); // Add the number of Answer to the CorrectAnswerListCounter CorrectAnswerListCounter = CorrectAnswerList.size(); // Initialize button array ButtonArray = new ArrayList<Button>(); for (int current = 0; current < list.size(); current++) { Answer ThisAns = list.get(current); // Create a table row TableRow tr = new TableRow(this); tr.setId(1000 + current); tr.setGravity(Gravity.CENTER); tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); /*TextView Tv = new TextView(this); Tv.setId(1000+current); Tv.setText(Html.fromHtml(ThisAns.get_AnswerText())); Tv.setTextColor(Color.WHITE); tr.addView(Tv); Table.addView(tr);*/ // Configure each button and add to row and then add row to table Button bt = new Button(this); bt.setId(1000 + current); bt.setText(Html.fromHtml(ThisAns.get_AnswerText())); bt.setTextColor(Color.BLACK); bt.setGravity(Gravity.CENTER); bt.setWidth(420); bt.setHeight(LayoutParams.WRAP_CONTENT); bt.setTextSize(12); // Add the correct answer to the button bt.setTag(ThisAns.get_Correct()); bt.setOnClickListener(this); // Add button the button array ButtonArray.add(bt); tr.addView(bt); Table.addView(tr); } } }
@Override public View getView(int position, View convertView, ViewGroup parent) { /* * This method is executed for each item in the list in order to populate it with related data. * */ View row = convertView; Answer answer = answers.get(position); inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (answer != null) { row = inflater.inflate(R.layout.answer_row, parent, false); TextView answerBody = (TextView) row.findViewById(R.id.answerBody); int colorPos = position % colors.length; // The answer accepted as the Correct answer has a green background if (answer.is_accepted()) { row.setBackgroundColor(Color.parseColor("#59F059")); answerBody.setText(Html.fromHtml("<b>Accepted Answer</b><br/>" + answer.getBody())); } else { row.setBackgroundColor(Color.parseColor(colors[colorPos])); answerBody.setText(Html.fromHtml(answer.getBody())); } TextView answerOwner = (TextView) row.findViewById(R.id.answerBodyOwner); answerOwner.setText( Html.fromHtml( "answered: " + answer.getCreation_date() + "<br/>By: " + answer.getOwner().getDisplay_name())); // display comments related to each answer if they exist. // In case they do not exist, hide the widgets used to display comments. if (answer.getComment_count() > 0) { TextView comments = (TextView) row.findViewById(R.id.answerComments); String comStr = "<b>Comments:</b><br/>"; ArrayList<Comment> coms = answer.getComments(); for (int i = 0; i < coms.size(); i++) { Comment c = coms.get(i); comStr += (i + 1) + ". " + c.getBody() + " <br/> By: " + c.getOwner().getDisplay_name() + " - " + c.getCreation_date() + "<br/><br/>"; } comments.setText(Html.fromHtml(comStr)); } else { TextView comments = (TextView) row.findViewById(R.id.answerComments); comments.setVisibility(View.INVISIBLE); View viewComments1 = row.findViewById(R.id.viewComments1); viewComments1.setVisibility(View.INVISIBLE); View viewComments2 = row.findViewById(R.id.viewComments2); viewComments2.setVisibility(View.INVISIBLE); } } return row; }
public static Answer getNewAnswer(String name) { return Answer.createAnswer(name, selectedDao); }
private Answer createAnswer(long id) { Answer answer = new Answer(); answer.setId(id); answer.setAnswerValues(createAnswerValues()); return answer; }
public static PersonCatory get(int order) { if (order == Answer.ordinal()) { return Answer; } return Asker; }
@Override /** * This method handles the voting on answers * * @param request request from user * @param response response back send to the user */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { WebAppDB db = new WebAppDB(); ResultSet answer1; db.createConnection(); try { db.setAutoCommit(); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } StringBuilder sb = new StringBuilder(); BufferedReader br = request.getReader(); String str = null; while ((str = br.readLine()) != null) { sb.append(str); } String data = new Gson().fromJson(sb.toString(), String.class); String upVotestr = data.substring(1, 2); String idstr = data.substring(3, data.length() - 1); Integer id = Integer.parseInt(idstr); Integer upVote = Integer.parseInt(upVotestr); ResultSet numOfLikesSet = db.executeQuery("select Likes as A from ANSWERS where AID = " + id.intValue()); ResultSet QIDSet = db.executeQuery("select QID as A from ANSWERS where AID = " + id.intValue()); String numOfLikesStr = ""; String QIDStr = ""; try { if (numOfLikesSet.next()) numOfLikesStr = numOfLikesSet.getString("A"); if (QIDSet.next()) QIDStr = QIDSet.getString("A"); int numOfLikesInt = Integer.parseInt( numOfLikesStr); // numOfLikesInt contains the number of likes at the current moment if (upVote == 1) numOfLikesInt++; else if (upVote == 0) numOfLikesInt--; if (upVote != null && id != null) { db.executeUpdate( "update ANSWERS set likes =" + numOfLikesInt + "where AID = " + id.intValue()); } List<Answer> answersToPresent = new ArrayList<Answer>(); answer1 = db.executeQuery( "select * from " + tableName + " WHERE QID=" + QIDStr + " order by Likes desc, Time asc"); while (answer1.next()) { // there is such an answer Answer A = new Answer(-1, -1, "", ""); A.setQID(Integer.parseInt(QIDStr)); A.setText(answer1.getString("Text")); A.setTime(answer1.getString("Time")); A.setUID(answer1.getString("UID")); A.setAID(answer1.getInt("AID")); A.setLikes(answer1.getInt("Likes")); answersToPresent.add(A); } answer1.close(); String json = new Gson().toJson(answersToPresent); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(json); response.getWriter().close(); db.closeConnection(); } catch (SQLException e) { e.printStackTrace(); } finally { db.closeConnection(); } }
public static ArrayList<IAnswer> getAnswerList() { return Answer.getAnswers(); }
@Test(dataProvider = "testData") public void testAnswer(int n, int expectedAnswer) { int answer = Answer.answer(n); assertEquals(answer, expectedAnswer); }
public static IAnswer getNewAnswer(boolean random) { return Answer.createAnwer(random, selectedDao); }
public static void main(String[] args) { List<String> question = new ArrayList<String>(); question = Questions.readQuestions(); BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); int count = 0, y = 0, numOfParticipants = 0; List<String> participantAnswers = new ArrayList<String>(); String value = ""; String result = ""; HashMap<Integer, String> output = new HashMap<Integer, String>(); Answer object = new Answer(); int answer; try { do { System.out.println("Enter your choice:"); System.out.println("1. Give Feedback"); System.out.println("2. Total Percentage Distribution"); System.out.println("3. Final Output"); System.out.println("4. Exit"); answer = Integer.parseInt(sc.readLine()); switch (answer) { case 1: { // If the user wants to do the Feedback and answer the questions numOfParticipants++; for (String s : question) { do { System.out.println(s); value = sc.readLine(); result = object.checkOption(value, s); } while (result.equals("")); participantAnswers.add(result); } output = object.storeAnswer( count, participantAnswers.get(0), participantAnswers.get(1), participantAnswers.get(2), output); count += 3; participantAnswers.clear(); break; } case 2: { // If the user wants the percentage for an option opted by the participants object.totalPercentage(output, numOfParticipants, count); break; } case 3: { // If the user wants to see all the answers for all participants object.display(output, question, numOfParticipants); break; } case 4: { // If the user wants to exit from the program System.out.println("Thans for visitng. Have a nice day, Bye"); System.exit(0); } default: { // If a user enters a value other than available options System.out.println("Enter a value from the available options"); break; } } System.out.println("Press 0 to continue or 1 to exit"); y = Integer.parseInt(sc.readLine()); } while (y == 0); } catch (Exception e) { System.out.println("Enter a valid integer value"); } }
public void add(Answer answer) { answers.put(answer.getQuestionText(), answer); }
@Override protected void onPreExecute() { super.onPreExecute(); callback.beforeExecution(); }