use of doc.mathobjects.GeneratedProblem in project OpenNotebook by jaltekruse.
the class ExpressionGenerator method generateProblem.
public GeneratedProblem generateProblem(int difficulty) {
GeneratedProblem newProblem = new GeneratedProblem();
ExpressionObject expressionObj = new ExpressionObject();
try {
newProblem.setDifficulty(difficulty);
newProblem.getListWithName(GeneratedProblem.GEN_LIST).getValues().clear();
((ListAttribute<UUIDAttribute>) newProblem.getListWithName(GeneratedProblem.GEN_LIST)).addValueWithString(getProblemID().toString());
Node[] n = generateExpression(difficulty);
expressionObj.setExpression(n[0].toStringRepresentation());
expressionObj.addCorrectAnswer(n[1].toStringRepresentation());
} catch (AttributeException e) {
e.printStackTrace();
} catch (NodeException e) {
e.printStackTrace();
}
getProblemHoldingDocument().getDocViewerPanel().drawObjectInBackground(expressionObj);
expressionObj.setParentContainer(newProblem.getParentContainer());
newProblem.addObjectFromPage(expressionObj);
return newProblem;
}
use of doc.mathobjects.GeneratedProblem in project OpenNotebook by jaltekruse.
the class Document method generateProblems.
public void generateProblems(Vector<ProblemGenerator> generators, Vector<Integer> frequencies, int numberOfProblems, String directions, boolean problemNumbers) {
for (ProblemGenerator gen : generators) {
gen.setProblemHoldingDocument(this);
try {
addGenerator(gen);
} catch (Exception e) {
// problem formula has already been added
}
}
int j = 0;
Vector<GeneratedProblem> newProblems = new Vector<>(numberOfProblems);
for (int i = 0; j < numberOfProblems; j++, i++) {
if (i < numberOfProblems / 3) {
newProblems.add(generators.get(pickRandomIndex(frequencies)).generateProblem(ProblemGenerator.EASY));
} else if (i < numberOfProblems * (2.0 / 3)) {
newProblems.add(generators.get(pickRandomIndex(frequencies)).generateProblem(ProblemGenerator.MEDIUM));
} else {
newProblems.add(generators.get(pickRandomIndex(frequencies)).generateProblem(ProblemGenerator.HARD));
}
}
layoutProblems(newProblems, directions, this, problemNumbers);
docPanel.repaint();
}
use of doc.mathobjects.GeneratedProblem in project OpenNotebook by jaltekruse.
the class Document method stripAnswers.
public boolean stripAnswers() {
Vector<MathObject> pageObjects;
Page p;
MathObject mObj;
int oldSize;
boolean problemsGenerated = false;
for (int i = 0; i < getPages().size(); i++) {
pageObjects = getPages().get(i).getObjects();
oldSize = pageObjects.size();
for (int j = 0; j < oldSize; j++) {
mObj = pageObjects.get(j);
if (mObj instanceof GeneratedProblem) {
((GeneratedProblem) mObj).generateNewProblem();
problemsGenerated = true;
j--;
oldSize--;
}
}
}
return problemsGenerated;
}
use of doc.mathobjects.GeneratedProblem in project OpenNotebook by jaltekruse.
the class Document method generateNewVersion.
public boolean generateNewVersion() {
Vector<MathObject> pageObjects;
MathObject mObj;
int oldSize;
boolean problemsGenerated = false;
for (int i = 0; i < getPages().size(); i++) {
pageObjects = getPages().get(i).getObjects();
oldSize = pageObjects.size();
for (int j = 0; j < oldSize; j++) {
mObj = pageObjects.get(j);
if (mObj instanceof GeneratedProblem) {
((GeneratedProblem) mObj).generateNewProblem();
problemsGenerated = true;
j--;
oldSize--;
} else if (mObj instanceof Grouping && ((Grouping) mObj).containsGeneratedProblems()) {
((Grouping) mObj).generateNewVersion();
problemsGenerated = true;
}
}
}
return problemsGenerated;
}
Aggregations