Contents

 

 1. Start

 

22. Lessons

 

33. Programming Environment

 

   Developing a program

      Function Declaration

      Karel delivery

      Main Program

 

   Editing

      Insert statement

      Delete a line

      Delete a function

      Delete main program

      Editing a function

      Editing a robot

 

   Compiling

 

   Executing

      Run

      Step By Step

      Tracing

 

   Save

   Save as

 

   Open

 

   Printing

 

   World Situation

 

   Menus

      File

      Edit

      Run

 

 

     

Karel tutorial

 

1.  START

 

When objectKarel starts the main menu of the application (Figure 1) appears with the following choices:

 

Figure 1. The main menu of Karel.

 

* Lessons: each consists of theory and one or more hands-on activities for familiarizing students with the concepts of the unit.

* Programming environment: integrated programming environment for developing, compiling, debugging and executing programs.

* Options: the user can select the language that will be used in the graphical user interface, which can be either English or Greek.

* Exit: exit from Karel.

2. LESSONS

 

After selecting a lesson – Introduction, Objects, Classes, Inheritance, Polymorphism, Overriding, Selection, Repetition – the user can see:

* the relative theory at the Theory card. The user can print the theory presented at the Theory card by pressing the button .

* at the Activities card (Figure 2) one or more hands-on activities that aim at a better understanding of theory and also at the gradual disclosure of the OOP concepts, the syntax and the semantics of the robots’ programming language.

 

Figure 2. The activity card of the unit “Classes”.

 

3. PROGRAMMING ENVIRONMENT

 

The main window of the programming environment, which is presented at Figure 3, gives the chance to:

* develop, save, open and edit,

* compile,

* debug &

* execute

a program.

 

 

Figure 3. The main window of the programming environment.

 

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 α program is described:

Class declaration:

1.     We select “New Function” from the menu “Program Development” and the window presented at Figure 4 appears.

2.     At the card “Function Declaration” (Figure 4) we declare the new function by using the existing template: first we define the return type and the name of the new function. New functions are declared by pressing the button "Declaration of New Function".

3.     At the card “Functions’ Definition” (Figure 5) we define the body of the functionsmethods through the menu “Commands”, which is automatically updated with the names of all the new (previously declared) functions.

4.    We select “Accept-Retunfrom 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.

 

Figure 4. The card “Class Declaration”.

 

Figure 5. The card “Functions’ Definition”.

 

Notes:

* We can shift from one card to another at any time and edit (see Function editing).

 

 

Delivery of robot:
  1. We select Delivery of Robot from the menu Program Development.
  2. In the dialog frame that is presented in Figure 5 we initialize Karel’s variables for representing its initial situation.
  3. We press the button Ok and we return to the programming environment, while the source code is updated.

 

Figure 6. The dialog frame “Delivery of robot”.

 

Development of the main program:
  1. We select from the menu Program Development the reserved word task, which marks the beginning of the main program.
  2. We deliver the robot.
  3. We select the appropriate instruction – function from the menu Program Development.
  4.  

Observations:

*  In order to Insert Comments:

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.

*  In order to Insert a Blank Line:

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.

* In order to edit a program (edit the robot, function, delete – insert statements between others) see the paragraph “Editing a Program” that follows.

 

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):
  1. We select the line that we want to be deleted.
  2. We select Delete } Line from the menu Edit.
Delete a function:

1.    We select Delete } Function from the menu Edit.

2.    If we have declared more than one functions, a dialog box appears in order to select the name of the function that we want to delete.

3.    In the dialog frame Confirmation we press Yes and the definition of the function is deleted from the source code.

Delete main program:
  1. We select Delete } Main Program from the menu Edit.
  2. In the dialog box Confirmation we press Yes.
Editing a function:

1.     We select Edit } Functions from the menu Edit and the window with the cards “Function Declarationand “Function’s Definitionappears with these cards informed.

2.     We make the changes that we want by moving freely between the two cards:

Changing the name of a function and its return type is accomplished in the template that appears on the left side of the card “Function Declaration”.

For the deletion of a function:

1.     We select the function from the card «Function 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 functionmethod we follow the steps mentioned above for the main program.

Editing robot Karel:
  1. We select Edit } Initial robot situation from the menu Edit.
  2. In the frame that appears we make the changes we want.
  3. We press the button Accept.

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 windowSave 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 F9 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 canat any time -  stop the execution by selecting Pause from the menu Run or pressing F10 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 ProgramWorld Situation

 

In objectKarel there is the ability to recall/open:

 

*   a Source CodeWorld Situation file, since they have been saved with same name:

1.     We select Open file } Source CodeWorld Situation from the menu File and the window presented in Figure 7 appears.

2.     Κάνουμε κλικ στο όνομα του αρχείου που θέλουμε.

3.     Πατάμε το κουμπί Άνοιγμα, οπότε εμφανίζεται ο πηγαίος κώδικας στο αριστερό μέρος του παραθύρου και η αρχική κατάσταση του κόσμου δεξιά.

 

*   a Source Code file by selecting Open file } Source Code from the menu File.

 

*   a World Situation file by selecting Open file } Source CodeWorld Situation from the menu File.

 

Figure 7. The dialog frame Open Source Code – World Situation file.

 

Saving a ProgramWorld Situation

 

In objectKarel the user can save:

 

*   the changes that have been made in the Source Code and World Situation files that are open and have the same name and extensions kpp and wld respectively, by selecting Save } Source Code – World Situation from the menu File.

 

*   the changes that have been made in the open Source Code file by selecting Save } Source Code from the menu File.

 

*   the changes that have been made in the open World Situation file by selecting Save } World Situation from the menu File.

 

Saving a ProgramWorld Situation with a different name

 

In the environment of objectKarel we have the ability to save with a different name:

 

* the files of the Source Code and the World Situation:

1.     We select Save As } Source CodeWorld 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.

 

* the current Source Code file by selecting Save As } Source Code from the menu File.

 

* the current World Situation file by selecting Save As } World Situation from the menu File.

 

Printing

 

There is the ability to print:

 

* the Source Code and the World Situation that are presented in the window by selecting Print } Source Code – World Situation from the menu File.

 

* the Source Code that is presented in the window by selecting Print } Source Code from the menu File.

 

*       the World Situation that is presented in the window by selecting Print } World Situation from the menu File.

 

 

World Situation

 

In order to add:

* a horizontal or vertical wall section we click on the available avenue or street respectively, between the desired corners.

* beepers we click on the desired corner so many times as the number of the beepers that we want to add.

 

In order to delete:

* a horizontal or vertical wall section we click on it.

*       beepers we right click on the desired corner so many times as the number of beepers that we want to delete.

*        

 

Menus

Menu File

 

New

Create a new Program – World Situation. 

 

Open file } Source Code World Situation              

Open a Source Code file and the corresponding World Situation file (the 2 files have the same name). 

 

Open file } Source Code

Open a Source Code file.  

 

Open file } World Situation              

Open a World Situation file.

 

Save } Source Code World Situation              

Save the changes that have been made in the Source CodeWorld Situation in the current (open) files.

 

Save } Source Code  

Save the changes that have been made in the Source Code in the current (open) file.

 

Save } World Situation              

Save the changes that have been made in the World Situation in the current (open) file.

 

Print } Source Code World Situation              

Print the current Source CodeWorld Situation.

 

Print } Source Code

Print the Source Code.

 

Print } World Situation              

Print the World Situation.

 

Exit

Exit from the programming environment.

 

Menu “Edit”

 

Insert } Comment

Insert a comment in the line of the source code that that the user has selected with the mouse.

 

Insert } Blank Line

Insert a blank line in the line of the source code that that the user has selected with the mouse.

 

Delete } Command

Delete the line of the source code that that the user has selected with the mouse.

 

Delete } Function

Delete the definition of a function.

 

Delete } Main Class

Delete the main program.

 

Edit } Functions

Edit one or more functions that have been declared by the user.

 

Edit } Initial Robot situation

Edit the robot’s position.

Menu “Run”

 

Compile

Compile the source code.

 

Run

Execute the program and present its result in the situation of the world.

 

Run Step by Step

Execute the next source code statement.

 

Tracing

Execute the program step by step with a predefined speed (selected by the user).

 

Pause

Termination of program execution.

 

Reset

The initial world situation is presented so to execute the program again.