Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. package edu.rutgers.elearning.component.italian.pte;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Random;
  7.  
  8. import edu.rutgers.elearning.component.pte.ProblemTemplateEngine;
  9. import edu.rutgers.elearning.component.pte.ProblemTemplateEngine.QuestionType;
  10. import edu.rutgers.elearning.component.questions.DecimalQuestionAnswer;
  11. import edu.rutgers.elearning.component.questions.GeneratedQuestion;
  12. import edu.rutgers.elearning.component.questions.OpenMultifieldQuestion;
  13. import edu.rutgers.elearning.component.questions.QuestionAnswer;
  14. import edu.rutgers.elearning.component.questions.StringQuestionAnswer;
  15. import edu.rutgers.elearning.component.questions.OpenMultifieldQuestion.AnswerField;
  16. import edu.rutgers.elearning.genchem.chem.CompoundElements;
  17. import edu.rutgers.elearning.genchem.chem.CompoundElements.Element;
  18. import edu.rutgers.elearning.genchem.dao.CompoundsDAO;
  19. import edu.rutgers.elearning.genchem.model.CompoundsModel;
  20. import edu.rutgers.elearning.util.math.SigfigNumber;
  21.  
  22. /**
  23. * PTE ID = 640
  24. * Template Name = Italian placement test part 4 question 1
  25. *
  26. * @author Travis Harrell
  27. */
  28. public class ItalianPlacementTestPart4P1 extends ProblemTemplateEngine
  29. {
  30. Random rand = new Random();
  31.  
  32. CompoundElements compound;
  33. ArrayList<CompoundsModel> compoundModels;
  34. Element element1;
  35. Element element2;
  36.  
  37. static String[] types = new String[2];
  38. static
  39. {
  40. types[0] = "IONIC";
  41. types[1] = "COVALENT";
  42. }
  43.  
  44. SigfigNumber mass1;
  45. SigfigNumber mass2;
  46.  
  47. public ItalianPlacementTestPart4P1(int problemtemplate_id, int[] criticalskill_ids, int debugmode, QuestionType type)
  48. {
  49. super(problemtemplate_id, criticalskill_ids, debugmode, type);
  50.  
  51. CompoundsDAO compoundsDAO = new CompoundsDAO();
  52. HashMap<String, Object> searchMap = new HashMap<String, Object>();
  53. List<Element> elements;
  54.  
  55. do
  56. {
  57. searchMap.put("number_of_elements", 2);
  58. searchMap.put("compound_type", types);
  59.  
  60. compoundModels = (ArrayList<CompoundsModel>) compoundsDAO.selectAs(searchMap);
  61. compound = new CompoundElements(compoundModels.get(rand.nextInt(compoundModels.size())));
  62.  
  63. elements = compound.getElements();
  64. }while(elements.size() != 2);//shouldnt matter but just in case
  65.  
  66. element1 = elements.get(0);
  67. element2 = elements.get(1);
  68.  
  69. mass1 = SigfigNumber.random(10.0, 99.0, 3);
  70. mass2 = (mass1.div(element1.getAtomic_weight())).mult(((double)element2.getCount()/(double)element1.getCount())).mult(element2.getAtomic_weight());
  71. }
  72.  
  73. public String getQuestionText()
  74. {
  75. String question = null;
  76.  
  77. question = "If you have a sample of a compound that contains " + mass1.toStringMaybeSciNotation() + " g of " + element1.getPeriodic_symbol()
  78. + " and " + mass2.toStringMaybeSciNotation() + " g of " + element2.getPeriodic_symbol() + ". What is the percent mass of " + element1.getPeriodic_symbol()
  79. + " in the sample? What is the percent mass of " + element2.getPeriodic_symbol() + " in the sample? How many moles of " + element1.getPeriodic_symbol()
  80. + " and " + element2.getPeriodic_symbol() + " do you have? What is the empirical formula?";
  81.  
  82. return question;
  83. }
  84.  
  85. public List<AnswerField> getMultiboxFields()
  86. {
  87. ArrayList<AnswerField> fields = new ArrayList<>();
  88.  
  89. SigfigNumber answer1 = (element1.getAtomic_weight().mult(element1.getCount())).div(compound.getMolarmass());
  90. SigfigNumber answer2 = (element2.getAtomic_weight().mult(element2.getCount())).div(compound.getMolarmass());
  91. SigfigNumber answer3 = mass1.div(element1.getAtomic_weight());
  92. SigfigNumber answer4 = mass2.div(element2.getAtomic_weight());
  93.  
  94. String answer5 = compound.getFormula();//update with string parser
  95. if(compound.getCompound_id() == 148 || compound.getCompound_id() == 346)
  96. {
  97. answer5 = "HO";
  98. }
  99.  
  100. DecimalQuestionAnswer answer1DecimalQuestion = new DecimalQuestionAnswer(1, "correct", answer1.doubleValue()-0.01, answer1.doubleValue()+0.01, answer1.toStringWithoutSciNotation());
  101. DecimalQuestionAnswer answer2DecimalQuestion = new DecimalQuestionAnswer(1, "correct", answer2.doubleValue()-0.01, answer2.doubleValue()+0.01, answer2.toStringWithoutSciNotation());
  102. DecimalQuestionAnswer answer3DecimalQuestion = new DecimalQuestionAnswer(1, "correct", answer3.doubleValue()-0.01, answer3.doubleValue()+0.01, answer3.toStringWithoutSciNotation());
  103. DecimalQuestionAnswer answer4DecimalQuestion = new DecimalQuestionAnswer(1, "correct", answer4.doubleValue()-0.01, answer4.doubleValue()+0.01, answer4.toStringWithoutSciNotation());
  104. StringQuestionAnswer answer5StringQuestion = new StringQuestionAnswer(1, "correct", answer5, false);
  105.  
  106. AnswerField field1 = new AnswerField("Mass % of " + element1.getPeriodic_symbol() + ": ", answer1DecimalQuestion, " %", "answer1");
  107. AnswerField field2 = new AnswerField("Mass % of " + element2.getPeriodic_symbol() + ": ", answer2DecimalQuestion, " %", "answer1");
  108. AnswerField field3 = new AnswerField("Moles of " + element1.getPeriodic_symbol() + ": ", answer3DecimalQuestion, " mol", "answer1");
  109. AnswerField field4 = new AnswerField("Moles of " + element2.getPeriodic_symbol() + ": ", answer4DecimalQuestion, " mol", "answer1");
  110. AnswerField field5 = new AnswerField("Empirical Formula: ", answer5StringQuestion, "", "answer1");
  111.  
  112. fields.add(field1);
  113. fields.add(field2);
  114. fields.add(field3);
  115. fields.add(field4);
  116. fields.add(field5);
  117.  
  118. return fields;
  119. }
  120.  
  121. @Override
  122. public GeneratedQuestion serveQuestion()
  123. {
  124. GeneratedQuestion gq = null;
  125. if (type == QuestionType.MULTIFIELD) {
  126. OpenMultifieldQuestion omq = new OpenMultifieldQuestion();
  127. omq.setFieldsPrefix("");
  128. omq.setFieldsPostfix("");
  129. omq.appendFields(getMultiboxFields());
  130. gq = omq;
  131. }
  132. if (gq != null) {
  133. gq.setQuestion_text(getQuestionText());
  134. gq.loadMetadata(problemtemplate_id);
  135. gq.setVersion(storeVersion());
  136. }
  137. return gq;
  138. }
  139.  
  140. public String storeVersion()
  141. {
  142. HashMap<String, Object> dataMap = new HashMap<String, Object>();
  143. dataMap.put("compound ", compound.getFormula());
  144. dataMap.put("element1 ", element1.getPeriodic_symbol());
  145. dataMap.put("element2 ", element2.getPeriodic_symbol());
  146. dataMap.put("mass1 ", mass1.toStringMaybeSciNotation());
  147. dataMap.put("mass2 ", mass2.toStringMaybeSciNotation());
  148.  
  149. return dataMap.toString();
  150. }
  151.  
  152. @Override
  153. public String getDebugInfo() {
  154. // TODO Auto-generated method stub
  155. return null;
  156. }
  157.  
  158. @Override
  159. public List<QuestionAnswer> getMultipleChoiceAnswers() {
  160. // TODO Auto-generated method stub
  161. return null;
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement