Search in sources :

Example 1 with GeneratedProblem

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;
}
Also used : ExpressionObject(doc.mathobjects.ExpressionObject) Node(expression.Node) GeneratedProblem(doc.mathobjects.GeneratedProblem) NodeException(expression.NodeException) AttributeException(doc.attributes.AttributeException) ListAttribute(doc.attributes.ListAttribute)

Example 2 with GeneratedProblem

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();
}
Also used : GeneratedProblem(doc.mathobjects.GeneratedProblem) AttributeException(doc.attributes.AttributeException) ProblemGenerator(doc.mathobjects.ProblemGenerator)

Example 3 with GeneratedProblem

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;
}
Also used : GeneratedProblem(doc.mathobjects.GeneratedProblem) MathObject(doc.mathobjects.MathObject)

Example 4 with GeneratedProblem

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;
}
Also used : GeneratedProblem(doc.mathobjects.GeneratedProblem) Grouping(doc.mathobjects.Grouping) MathObject(doc.mathobjects.MathObject)

Aggregations

GeneratedProblem (doc.mathobjects.GeneratedProblem)4 AttributeException (doc.attributes.AttributeException)2 MathObject (doc.mathobjects.MathObject)2 ListAttribute (doc.attributes.ListAttribute)1 ExpressionObject (doc.mathobjects.ExpressionObject)1 Grouping (doc.mathobjects.Grouping)1 ProblemGenerator (doc.mathobjects.ProblemGenerator)1 Node (expression.Node)1 NodeException (expression.NodeException)1