Compare Visual Basic syntax to Java syntax using JerooProblem description: This program will place a Jeroo at the beginning of row 4, and it will travel to the end of the row. If it sees a flower ahead, it will go around it on the right, if a net, it will go around on the left
| Java solution | Visual Basic solution | |
method main(){
Jeroo Thor = new Jeroo(4,0,12);
// keep going across the row, as long as I
// haven't run into the water
while (!Thor.isWater(AHEAD)){
// if flower ahead, go around on right
// else if net, go around on left
if (Thor.isFlower(AHEAD))
Thor.goAroundRight();
else if (Thor.isNet(AHEAD))
Thor.goAroundLeft();
else
Thor.hop();
} // end of while
}
|
Sub main()
Dim Thor as Jeroo = new Jeroo(4,0,12)
' keep going across the row, as long as I
' haven't run into the water
While NOT Thor.isWater(AHEAD)
' if flower ahead, go around on right
' else if net, go around on left
IF Thor.isFlower(AHEAD)THEN
Thor.goAroundRight()
elseif Thor.isNet(AHEAD)THEN
Thor.goAroundLeft()
Else
Thor.hop()
End If
End While
End Sub |
|
// go around on the flower's right side
method goAroundRight(){
turn(RIGHT);
hop();
turn(LEFT);
hop();
hop();
turn(LEFT);
hop();
turn(RIGHT);
} |
' go around on the flower's right side
Sub goAroundRight()
turn(RIGHT)
hop()
turn(LEFT)
hop()
hop()
turn(LEFT)
hop()
turn(RIGHT)
End Sub |