T
- the type of the result(s)public abstract class AlgorithmExercise<T>
extends java.lang.Object
AlgorithmStep
.
requestSolution()
method and the examine(Object[], AlgorithmState)
method.beforeRequestSolution(AlgorithmState)
and afterRequestSolution(boolean)
to be notified before and after a solution
is/was requested.
getApplySolutionToAlgorithm()
and applySolutionToAlgorithm(AlgorithmState, Object[])
to apply a correct solution
the user has given to the algorithm.requestSolution()
method returns null
and the exercise has related views.
The message explains that the user has to solve the exercise in the corresponding view(s) and afterwards click on the solve-button.hasInputHint()
and getInputHintMessage(LanguageFile, String)
to create a custom input hint.
getLastFailedHintMessage()
to return descriptions that inform the user about why the exercise is failed currently.
SolveExercisePane.showDialog(lavesdk.algorithm.plugin.PluginHost, AlgorithmExercise, lavesdk.gui.dialogs.SolveExerciseDialog.SolutionEntry[], lavesdk.language.LanguageFile, String, String)
to display a customizable input dialog where the user can enter solutions for an exercise.Modifier and Type | Class and Description |
---|---|
static class |
AlgorithmExercise.ExamResult
The result of an examination.
|
Constructor and Description |
---|
AlgorithmExercise(java.lang.String text)
Creates a new exercise.
|
AlgorithmExercise(java.lang.String text,
float credits)
Creates a new exercise.
|
AlgorithmExercise(java.lang.String text,
float credits,
View view)
Creates a new exercise.
|
AlgorithmExercise(java.lang.String text,
float credits,
View[] views)
Creates a new exercise.
|
Modifier and Type | Method and Description |
---|---|
protected void |
afterRequestSolution(boolean omitted)
This method is invoked after the user has entered a solution.
|
protected void |
applySolutionToAlgorithm(AlgorithmState state,
T[] solutions)
Applies the specified solution to the given
AlgorithmState . |
protected void |
beforeRequestSolution(AlgorithmState state)
This method is invoked before the user enters a solution.
|
protected boolean |
doAutoExamine(AlgorithmState state,
java.lang.String[] keys,
T[] results)
Does an automatic examination of the results a user has entered as the solution of the exercise.
|
protected void |
entered()
This method is invoked each time the exercise is entered.
|
protected abstract boolean |
examine(T[] results,
AlgorithmState state)
Examines the results the user has entered as the solution of the exercise.
|
protected void |
exited()
This method is invoked each time the exercise is exited.
|
protected boolean |
getApplySolutionToAlgorithm()
Indicates whether the solution of the exercise should be applied to the algorithm before the related step is executed.
|
float |
getCredits()
The credits of the exercise.
|
Annotation |
getInputHintMessage(LanguageFile langFile,
java.lang.String langID)
Gets the input hint message that is displayed to the user if
requestSolution() returns null . |
Annotation |
getLastFailedHintMessage()
Gets the description of the last failure of the exercise.
|
protected java.lang.String |
getResultAsString(T result,
int index)
Gets the specified result as a string representation.
|
protected java.lang.String |
getSolutionAsString()
Gets the current solution of the exercise as a string representation.
|
java.lang.String |
getText()
Gets the text of the exercise.
|
void |
giveUp()
Gives up the exercise which indicates that the user cannot solve the exercise.
|
boolean |
hasInputHint()
Indicates whether the input hint should be displayed if
requestSolution() returns null . |
boolean |
hasLastFailedHint()
Indicates whether the exercise has a description of the last failure.
|
protected abstract T[] |
requestSolution()
Requests the results of the exercise meaning that the user should input the value or values of the solution.
|
boolean |
solve()
Solves the exercise meaning that the solution of the exercise is requested from the user by using
requestSolution() . |
public AlgorithmExercise(java.lang.String text) throws java.lang.IllegalArgumentException
AlgorithmExercise(String, float)
to specify credits the user can reach if
the exercise is succeeded.text
- the text of the exercise (use html tags to format the text)java.lang.IllegalArgumentException
- public AlgorithmExercise(java.lang.String text, float credits) throws java.lang.IllegalArgumentException
text
- the text of the exercise (use html tags to format the text)credits
- the credits of the exercise the user can reach or 0.0f
if the exercise does not have creditsjava.lang.IllegalArgumentException
- < 0.0f
public AlgorithmExercise(java.lang.String text, float credits, View view) throws java.lang.IllegalArgumentException
text
- the text of the exercise (use html tags to format the text)credits
- the credits of the exercise the user can reach or 0.0f
if the exercise does not have creditsview
- the view in which the exercise has to be solved/the solution has to be entered or null
if there is no related view (a valid view will be displayed (if the view is invisible) and the view will be highlighted with an enclosing border to show the user where to enter the solution)java.lang.IllegalArgumentException
- < 0.0f
public AlgorithmExercise(java.lang.String text, float credits, View[] views) throws java.lang.IllegalArgumentException
text
- the text of the exercise (use html tags to format the text)credits
- the credits of the exercise the user can reach or 0.0f
if the exercise does not have creditsviews
- the views in which the exercise has to be solved/the solution has to be entered or null
if there are no related views (valid views will be displayed (if a view is invisible) and the views will be highlighted with an enclosing border to show the user where to enter the solution)java.lang.IllegalArgumentException
- < 0.0f
public final java.lang.String getText()
public final float getCredits()
0.0f
if the exercise does not have creditspublic final boolean solve()
requestSolution()
.
After that the controller of the exercise is notified to continue with working if the request is no canceled.true
if the user entered a solution or false
if the user has canceled the requestpublic final void giveUp()
public Annotation getInputHintMessage(LanguageFile langFile, java.lang.String langID)
requestSolution()
returns null
.
langFile
- the language file of the host systemlangID
- the language id that is selected in the host systemhasInputHint()
,
Annotation
public boolean hasInputHint()
requestSolution()
returns null
.
AlgorithmExercise(String, float, View[])
).
true
if an input hint should be shown otherwise false
getInputHintMessage(LanguageFile, String)
public Annotation getLastFailedHintMessage()
private String lastFailHintMsg = ""; //... public Annotation getLastFailHintMessage() { return lastFailHintMsg.isEmpty() ? null : new Annotation(lastFailHintMsg); } //... protected boolean examine(...[] results, AlgorithmState state) { // some initializations... // clear the last message lastFailHintMsg = ""; // separate the individual failures where Failure1 might be results[0] == null or something like this if(Failure1) lastFailHintMsg = "You have selected the wrong ..."; else if(Failure2) lastFailHintMsg = "You have entered the wrong ..."; // else if ... return ...; }
null
if there is no description availablepublic final boolean hasLastFailedHint()
true
if the exercise has a hint (this is the case if the exercise is not given up currently and getLastFailedHintMessage()
is not null
) otherwise false
protected final java.lang.String getSolutionAsString()
getResultAsString(Object, int)
protected java.lang.String getResultAsString(T result, int index)
null
the string representation is "-"
otherwise it is
result.toString()
.
result
- the result or null
index
- the index of the result in the array of results returned by requestSolution()
protected abstract T[] requestSolution()
requestSolution()
should return the selected vertex of the graph or null
if the user does not have selected a
vertex:
... public VisualVertex[] requestSolution() { if(graphView.getSelectedVertexCount() != 1) return null; else return new VisualVertex[] { graphView.getSelectedVertex(0) }; } ...
null
if the user canceled the requestprotected abstract boolean examine(T[] results, AlgorithmState state)
results
- the results requested by requestSolution()
state
- the current state of the algorithmtrue
if the solution is correct otherwise false
doAutoExamine(AlgorithmState, String[], Object[])
protected final boolean doAutoExamine(AlgorithmState state, java.lang.String[] keys, T[] results) throws java.lang.IllegalArgumentException
A
and B
to solve the exercise. To examine the solution automatically it must be
assumed that these fields (described by the keys) are also available in the algorithm state.... protected boolean examine(T[] results, AlgorithmState state) { return doAutoExamine(state, new String[] { "A", "B" }, results); } ...
state
- the current state of the algorithmkeys
- the keys of the result fields in the state (should fit to the result fields)results
- the results requested by requestSolution()
true
if the solution is correct otherwise false
java.lang.IllegalArgumentException
- results.length != keys.length
protected void beforeRequestSolution(AlgorithmState state)
state
- the state of the algorithm (can be used to present current data to the user)afterRequestSolution(boolean)
protected void afterRequestSolution(boolean omitted)
omitted
- true
if the exercise is omitted meaning the user has given up to solve the exercise otherwise false
beforeRequestSolution(AlgorithmState)
protected boolean getApplySolutionToAlgorithm()
applySolutionToAlgorithm(AlgorithmState, Object[])
too.true
if the solution should be applied to the algorithm otherwise false
protected void applySolutionToAlgorithm(AlgorithmState state, T[] solutions)
AlgorithmState
.
examine(Object[], AlgorithmState)
that is, only correct solutions
can be applied to the algorithm.
AlgorithmRTE.adoptState(int, AlgorithmState)
).getApplySolutionToAlgorithm()
and return true
you have to override this method too.state
- the statesolutions
- the solutions of the user by requestSolution()
protected void entered()
protected void exited()