Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.rutgers.elearning.component.italian.pte;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Random;
- import edu.rutgers.elearning.component.pte.ProblemTemplateEngine;
- import edu.rutgers.elearning.component.pte.ProblemTemplateEngine.QuestionType;
- import edu.rutgers.elearning.component.questions.DecimalQuestionAnswer;
- import edu.rutgers.elearning.component.questions.GeneratedQuestion;
- import edu.rutgers.elearning.component.questions.OpenMultifieldQuestion;
- import edu.rutgers.elearning.component.questions.QuestionAnswer;
- import edu.rutgers.elearning.component.questions.StringQuestionAnswer;
- import edu.rutgers.elearning.component.questions.OpenMultifieldQuestion.AnswerField;
- import edu.rutgers.elearning.genchem.chem.CompoundElements;
- import edu.rutgers.elearning.genchem.chem.CompoundElements.Element;
- import edu.rutgers.elearning.genchem.dao.CompoundsDAO;
- import edu.rutgers.elearning.genchem.model.CompoundsModel;
- import edu.rutgers.elearning.util.math.SigfigNumber;
- /**
- * PTE ID = 640
- * Template Name = Italian placement test part 4 question 1
- *
- * @author Travis Harrell
- */
- public class ItalianPlacementTestPart4P1 extends ProblemTemplateEngine
- {
- Random rand = new Random();
- CompoundElements compound;
- ArrayList<CompoundsModel> compoundModels;
- Element element1;
- Element element2;
- static String[] types = new String[2];
- static
- {
- types[0] = "IONIC";
- types[1] = "COVALENT";
- }
- SigfigNumber mass1;
- SigfigNumber mass2;
- public ItalianPlacementTestPart4P1(int problemtemplate_id, int[] criticalskill_ids, int debugmode, QuestionType type)
- {
- super(problemtemplate_id, criticalskill_ids, debugmode, type);
- CompoundsDAO compoundsDAO = new CompoundsDAO();
- HashMap<String, Object> searchMap = new HashMap<String, Object>();
- List<Element> elements;
- do
- {
- searchMap.put("number_of_elements", 2);
- searchMap.put("compound_type", types);
- compoundModels = (ArrayList<CompoundsModel>) compoundsDAO.selectAs(searchMap);
- compound = new CompoundElements(compoundModels.get(rand.nextInt(compoundModels.size())));
- elements = compound.getElements();
- }while(elements.size() != 2);//shouldnt matter but just in case
- element1 = elements.get(0);
- element2 = elements.get(1);
- mass1 = SigfigNumber.random(10.0, 99.0, 3);
- mass2 = (mass1.div(element1.getAtomic_weight())).mult(((double)element2.getCount()/(double)element1.getCount())).mult(element2.getAtomic_weight());
- }
- public String getQuestionText()
- {
- String question = null;
- question = "If you have a sample of a compound that contains " + mass1.toStringMaybeSciNotation() + " g of " + element1.getPeriodic_symbol()
- + " and " + mass2.toStringMaybeSciNotation() + " g of " + element2.getPeriodic_symbol() + ". What is the percent mass of " + element1.getPeriodic_symbol()
- + " in the sample? What is the percent mass of " + element2.getPeriodic_symbol() + " in the sample? How many moles of " + element1.getPeriodic_symbol()
- + " and " + element2.getPeriodic_symbol() + " do you have? What is the empirical formula?";
- return question;
- }
- public List<AnswerField> getMultiboxFields()
- {
- ArrayList<AnswerField> fields = new ArrayList<>();
- SigfigNumber answer1 = (element1.getAtomic_weight().mult(element1.getCount())).div(compound.getMolarmass());
- SigfigNumber answer2 = (element2.getAtomic_weight().mult(element2.getCount())).div(compound.getMolarmass());
- SigfigNumber answer3 = mass1.div(element1.getAtomic_weight());
- SigfigNumber answer4 = mass2.div(element2.getAtomic_weight());
- String answer5 = compound.getFormula();//update with string parser
- if(compound.getCompound_id() == 148 || compound.getCompound_id() == 346)
- {
- answer5 = "HO";
- }
- DecimalQuestionAnswer answer1DecimalQuestion = new DecimalQuestionAnswer(1, "correct", answer1.doubleValue()-0.01, answer1.doubleValue()+0.01, answer1.toStringWithoutSciNotation());
- DecimalQuestionAnswer answer2DecimalQuestion = new DecimalQuestionAnswer(1, "correct", answer2.doubleValue()-0.01, answer2.doubleValue()+0.01, answer2.toStringWithoutSciNotation());
- DecimalQuestionAnswer answer3DecimalQuestion = new DecimalQuestionAnswer(1, "correct", answer3.doubleValue()-0.01, answer3.doubleValue()+0.01, answer3.toStringWithoutSciNotation());
- DecimalQuestionAnswer answer4DecimalQuestion = new DecimalQuestionAnswer(1, "correct", answer4.doubleValue()-0.01, answer4.doubleValue()+0.01, answer4.toStringWithoutSciNotation());
- StringQuestionAnswer answer5StringQuestion = new StringQuestionAnswer(1, "correct", answer5, false);
- AnswerField field1 = new AnswerField("Mass % of " + element1.getPeriodic_symbol() + ": ", answer1DecimalQuestion, " %", "answer1");
- AnswerField field2 = new AnswerField("Mass % of " + element2.getPeriodic_symbol() + ": ", answer2DecimalQuestion, " %", "answer1");
- AnswerField field3 = new AnswerField("Moles of " + element1.getPeriodic_symbol() + ": ", answer3DecimalQuestion, " mol", "answer1");
- AnswerField field4 = new AnswerField("Moles of " + element2.getPeriodic_symbol() + ": ", answer4DecimalQuestion, " mol", "answer1");
- AnswerField field5 = new AnswerField("Empirical Formula: ", answer5StringQuestion, "", "answer1");
- fields.add(field1);
- fields.add(field2);
- fields.add(field3);
- fields.add(field4);
- fields.add(field5);
- return fields;
- }
- @Override
- public GeneratedQuestion serveQuestion()
- {
- GeneratedQuestion gq = null;
- if (type == QuestionType.MULTIFIELD) {
- OpenMultifieldQuestion omq = new OpenMultifieldQuestion();
- omq.setFieldsPrefix("");
- omq.setFieldsPostfix("");
- omq.appendFields(getMultiboxFields());
- gq = omq;
- }
- if (gq != null) {
- gq.setQuestion_text(getQuestionText());
- gq.loadMetadata(problemtemplate_id);
- gq.setVersion(storeVersion());
- }
- return gq;
- }
- public String storeVersion()
- {
- HashMap<String, Object> dataMap = new HashMap<String, Object>();
- dataMap.put("compound ", compound.getFormula());
- dataMap.put("element1 ", element1.getPeriodic_symbol());
- dataMap.put("element2 ", element2.getPeriodic_symbol());
- dataMap.put("mass1 ", mass1.toStringMaybeSciNotation());
- dataMap.put("mass2 ", mass2.toStringMaybeSciNotation());
- return dataMap.toString();
- }
- @Override
- public String getDebugInfo() {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public List<QuestionAnswer> getMultipleChoiceAnswers() {
- // TODO Auto-generated method stub
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement