This tutorial shows you how to create and run a simple Jeroo program. More examples and more information about using Jeroo can be found in the tutorial document "Introduction to Jeroo" which is available from Jeroo's homepage (www.jeroo.org).
Santong Island
Conceptual Model
Santong Island is represented as a grid consisting of 24 rows and 24 columns.
The rows are numbered from 0 to 23 starting in the north (top) row.
The columns are numbered from 0 to 23 starting in the west(left) columm.
The location of a cell is specified as a pair of the form (r ,c), where r represents the row number of the cell, and c represents its column number. For example, the pair (4,5) specifies the cell in row number 4 and column number 5.
Appearance on the Screen
Practice
Watch the Cursor Location field change as you move the cursor over the island. This field displays the current location of the cursor on the island.
A Problem to Solve
A Jeroo starts in the northwest corner of the island, facing East, with no flowers.
There is a flower at location (0,4).
There is a net at location (2.4).
There are no other flowers, nets, Jeroos or water on the island.
Write a program that will direct the Jeroo to pick the flower, use the flower to disable the net, and finish at the net's starting location facing EAST.
What Can A Jeroo Do?
To solve this problem, we need to know about Jeroo's action methods. A Jeroo can perform the seven separate actions listed below. To find out more about Jeroo's action methods, click on the "Help" menu, select the "Language Summary" item, then select the "Action Methods" tab from the Language Summary window.
A Jeroo can
hop one space
hop several spaces
turn left or right
pick a flower from its current location
plant a flower at its current location
give a flower to an adjacent Jeroo
toss a flower to disable a net
Solution Plan
Observations
The Jeroo starts facing East.
The flower is exactly 4 spaces ahead of the Jeroo.
The net is exactly 2 spaces South of the flower.
The Jeroo's ending position will be the net's original position.
The Jeroo must be facing East at the end.
Algorithm
Let's name the Jeroo Kim.
Instantiate (create) Kim
Kim hop four spaces
Kim pick the flower
Kim turn right
Kim hop once
Kim toss the flower to disable the net
Kim hop once
Kim turn left
The Program's Source Code
It's quite easy to convert the algorithm into a valid Jeroo program. The complete program is shown below.
Sub main()
'--- instantiate the Jeroo ---
Dim Kim as Jeroo = new Jeroo()
'--- get the flower ---
Kim.hop(4)
Kim.pick()
'--- disable the net ---
Kim.turn(RIGHT)
Kim.hop()
Kim.toss()
'--- finish up ---
Kim.hop()
Kim.turn(LEFT)
End Sub '===== main() =====
Writing The Program
This portion of the tutorial uses the tab panes in the left half of the Jeroo frame.
Normally, you would type the entire program into the "main method" tab in the left half of the Jeroo window. There are three ways to get this tutorial program into the "main method" tab.
Click on the "main method" tab and type the code as it appears above. The capitalization and punctuation are important.
Copy the program above and paste it into the "main method" tab.
Click on the Copy The Code button below.
The first method is good practice, but you may want to use one of the other two.
Editing The Island
This portion of the tutorial uses the Island Edit menu and/or the corresponding toolbar buttons.
You need to use the mouse (or other pointing device) to place flowers, nets, and water on the island.
To add or remove flowers, either click the button on Jeroo's toolbar, or select Plant Flowers from the Island Edit menu.
To add or remove nets, either click the button on Jeroo's toolbar, or select Set Nets from the Island Edit menu.
To add or remove water, either click the button on Jeroo's toolbar, or select Add Water from the Island Edit menu.
The cursor always indicates the kind of object that you are adding to the island.
Click the left mouse button to place an object in the current cell, replacing anything that might be there already.
Hold the left mouse button down and move the mouse to place several adjacent objects on the island.
Click the right mouse button to remove an object from the current cell.
Hold the right mouse button down and move the mouse to remove several objects from the island.
Practice
Practice placing and removing flowers, nets, and water until you are comfortable with the process. Notice that the Cursor Location field under the island always shows you the cursor's location. This makes it easier to place objects in specific locations.
When you are finished, clear the island by pressing the button on Jeroo's toolbar or by selecting Clear Island from the Island Edit menu.
Do It For Real
Configure the island for this problem.
Clear the island.
Place a single flower at location (0,4).
Place a single net at location (2,4).
Running The Program
This portion of the tutorial uses the Run menu and/or the corresponding toolbar buttons. We will study ways to run a program, and we will see what happens when a Jeroo hops into a net or into the water.
Make sure that the program is identical to that shown above. The source code, but not the island, is automatically saved each time you run a program. Since you have not yet saved the program, you will be asked to provide a file name the first time you run it. This is a one-time event.
Basic Running
Click the button on Jeroo's toolbar or select Run Continuously from the Run menu to run the program.
There are several things to notice when you run the program.
Each Jeroo is represented by an arrow that shows the Jeroo's location and direction. A program can have up to four Jeroo's. Each is represented by an arrow with a unique shape and color.
A status panel under the island keeps track of each Jeroo, showing its name, its direction, and the number of flowers in its pouch. In our tutorial program, this panel has the following appearance just before Kim tosses a flower into the net. .
Each statement in the program is highlighted just before it is executed.
A message area under the source code shows the status of the program.
When you are finished, click the button on Jeroo's toolbar, or select Reset from the Run menu to reset the program and restore the island to its starting appearance.
Changing Speeds
The Run Speed menu and its associated slider can be used to change the speed at which the program executes. Try running the program at different speeds. Be sure to reset the program after each run.
Running Stepwise
Sometimes it helps to run the program one step at a time. This can be useful when we are trying to learn a new feature of the program or trying to locate the source of an error.
Click the button or select Run Stepwise from the Run menu to start running the program step-by-step.
The first time you press the "stepwise" button, the first statement to be executed will be highlighted.
Each time after the first, the highlighted line will be executed, and the next statement to execute will be highlighted.
Changing Modes and Speeds
Jeroo allows you to switch back and forth between running stepwise and continuously. Jeroo also allows you to stop a program or change speeds while a program is running.
Click the button on Jeroo's toolbar or select Run Continuously from the Run menu to switch from running stepwise to continuously.
Click the button on Jeroo's toolbar or select Pause from the Run menu to pause a program that is running continuously. After a program has been paused, you can switch to running stepwise or change speeds and resume running continuously at the new speed.
Click the button on Jeroo's toolbar or select Stop Run from the Run menu to stop a program.
Water and Nets
This activity shows what happens when a Jeroo hops into a net or into the water. As you learn more about Jeroo, you will learn how to detect and avoid nets, water, and other Jeroos.
Place a net at location (0,2) on the island. Run the program and watch what happens. Notice that an error message appears in the area under the source code tabs.
Replace the net with water. Run the program again and watch what happens. Be sure to read the error message.
A similar thing happens when one Jeroo bumps into another.
What's Next?
If you want to learn more about programming with Jeroo, work through the tutorial document "Introduction to Jeroo" which is available from Jeroo's homepage (www.jeroo.org).