1. Start 22. Lessons |
objectKarel tutorial
1. START
When
objectKarel starts the main menu of the application
(Figure 1) appears with the following choices:
2. LESSONS
After selecting a lesson – Introduction,
Objects, Classes, Inheritance, Polymorphism, Overriding, Selection,
Repetition – the user can see:
3. PROGRAMMING ENVIRONMENT
The main window
of the programming environment, which is presented at Figure 3, gives the
chance to:
a program.
Developing a Program
Developing a program is accomplished through the menu
“Program Development” (Figure 3) and interacting with the system
through dialog boxes. Next, the process of developing an
object-oriented program is described: Class declaration:
1. We select “Class/Method
Declaration” from the menu “Program Development” and
the window presented at Figure 4 appears. 2.
At
the card “Class Declaration” (Figure 4) we declare the
new class by using the existing template: first we define the name of the new
class within the text field after the reserved word class, and then we choose
from the list the parent class. Following, by pressing the button
"Declaration of New method" a list appears from which we
choose the type of the value - void or bool - which
the new method will return and defines its name. 3.
At
the card “Methods’ Definition” (Figure 5) we define the
body of the methods through the menu “Commands”, which is automatically updated with the names of all the new
(previously declared) methods. 4. We select “Accept-Retun”
from the menu “File” or press the homonym button and
return to the main window of the programming environment, while the source
code and the menu “Program Development” are updated.
Notes:
Object (robot) construction:
Development of the main program:
Observations:
1. We select (click on) the
line of
the source
code where
the comment will be
inserted. 2. We select Insert 4 Comment from the menu
Edit. 3. We write the
comment in
the window
that appears. 4. We close the window.
1. We select the
line of
the source
code where
the blank
line will
be inserted (the lines from
this position will move downwards). 2. We select Insert 4 Blank Line from the menu Edit.
Editing
a Program
Editing a program is accomplished through the
menu Edit, that
gives us the ability to: Insert a statement between others:
1. We select the line where we want
the statement to be inserted (the statements from this line move downwards). 2. We select form the menu Program Development the statement that we want to be inserted. Delete a line (statement, comment, blank line):
Delete a class:
1. We select Delete } Class from the menu
Edit. 2. If we have declared more than one class,
a dialog box appears in
order to select the name of the class that we want to delete. 3. In
the dialog
frame Confirmation we press
Yes and the declaration
of the class is deleted from the source code. Delete main program:
Editing
a class:
1. We select Edit
} Class from the menu Edit and the
window with
the cards
“Class Declaration” and “Method’s Definition” appears with these cards informed. 2. We make the changes that we
want by moving freely between the two cards: Changing the name of the class, the parent class
and the
methods is accomplished in the template that
appears on the left side of the card “Class Declaration”. For the deletion of a method: 1. We select the
method from the card
«Class Declaration». 2. We select Delete
} Line from the menu
Edit. In order to
insert a comment, a blank line and a statement between others in
the definition of a method we follow the steps mentioned above for the main
program. Editing a robot:
Compiling a Program
In order to compile a program: 1.
We select Compile from
the menu Run. 2.
If we have not saved the source code, the window “Save Source Code As …” appears in order to save the source code. 3. In the pane that stretches across the bottom of the window the errors of the program and the warnings
appear. By double clicking on an error/warning
message, both the line of the error
message and the line of the source code were the error is located is coloured
with the same colour. 4. If there are errors we must correct them and compile again the program so as to be able to run the program with one of the available ways that are described below. Executing a Program
Since a program has been successfully compiled we can execute it with one of the following ways: Run:
By selecting Run from the menu Run or pressing F6 from the keyboard the result
of program execution is
presented in
the World
Situation. If a
logic error is
detected then a message that explains the
error is appeared, otherwise a message that informs us that the execution of
the program finished successfully appears. Step by step execution (controlled
by the user):
We select Run Step By Step from the menu Run or pressing F8 from the keyboard in order for the next line of the
source code to be executed.
The current statement is highlighted by changing the color of its background, while the result of its execution appears in the situation of the world. Furthermore, the statement is semantically analyzed in the pane that stretches across
the bottom of the window. Tracing:
This choice gives
us the
ability to
execute a
program step by step with a predefined speed. Specifically, 1. We
select Tracing from the menu
Run. 2. In
the dialog
frame that
appears we
select the
tracing speed.
In
the last
two ways
of executing a program the user
can – at
any time
- stop the execution by selecting Pause from the menu Run or pressing F5 from the
keyboard. In
order to
execute again a program we must first select Reset from
the menu Run or press F7. In
the case
that does
not appear
an error
shutoff (logic error) the user is informed for the successful termination of the program. Opening a Program
– World Situation
In objectKarel there is
the ability to recall/open:
1. We select Open file } Source Code – World Situation from the menu File and the window presented in Figure 7 appears. 2. We click on the name of the file we
want to open. 3. We press the button Open, and we are presented with the source code in the
left side of the window and the initial situation of the world on the right.
Saving a Program
– World Situation
In objectKarel the user
can save:
Saving
a Program
– World Situation with a
different name
In
the environment of objectKarel we
have the
ability to
save with a different
name:
1. We select Save As } Source Code – World Situation from the menu
File. 2. In
the dialog
frame that
appears we
give the
new name
for the source code file (extension kpp)
and the world situation file (extension wld). 3. We press the button Save.
Printing
There is the ability to print:
World
Situation
In order to add:
In order to delete:
Menus
Menu “File”
Menu “Edit”
Menu “Run”
|