|
|
|
|
|
|
|
Advanced Topics in JerooRecursion with Custom MethodsRecursion in Jeroo
Recursion 1) Identify the base case in the code below and complete the program so that the recursion works. Start the Jeroo in the top left corner. Your objective is to complete the
go() method such that the Jeroo makes its way to the flower and picks it.
method go(){
if(isFlower(AHEAD)){
pick();
}
else if(isWater(AHEAD)){
turn(RIGHT);
hop();
turn(RIGHT);
hop();
//after we turned around
// call ourself again
go();
}
else if(isNet(AHEAD)){
//you should do this part
//do not use any kind of loop
}
else{
hop();
go();
}
}
Jeroo Activities for recursionDownload Island Files for these two activities
More examples of recursive methods
method recusiveMethod() {
if(!isWater(AHEAD))
hop();
else{
turn(RIGHT);
recusiveMethod();
}
}
method recursiveMovement(){
if(isNet(AHEAD)){
turn(RIGHT);
hop();
}
else{
if(isWater(AHEAD) )
turn(RIGHT);
else
hop();
recursiveMovement();
}
}
Recursive Activities |