Contents

 

 1. Start

 

22. Lessons

 

33. Programming Environment

 

   Developing a program

      Class Declaration

      Object construction

      Main Program

 

   Editing

      Insert statement

      Delete a line

      Delete a class

      Delete main program

      Editing a class

      Editing a robot

 

   Compiling

 

   Executing

      Run

      Step By Step

      Tracing

 

   Save

   Save as

 

   Open

 

   Printing

 

   World Situation

 

   Menus

      File

      Edit

      Run

 

 

     

objectKarel 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 objectKarel.

 

* 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 objectKarel.

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 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-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 “Methods’ Definition”.

 

Notes:

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

* When we declare a new class we can delete everything we have written by selecting Delete all from the menu Edit or pressing the button .

 

Object (robot) construction:
  1. We select Construction of Robot from the menu Program Development.
  2. In the dialog frame that is presented in Figure 5 we select which one of the available classes will be the parent of the robot, we declare its name and initialize its properties.
  3. We press the button Ok and we return to the programming environment, while the source code is updated.

 

Figure 6. The dialog frame “Construct an object (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 construct the robot or robots that are needed.
  3. We select the appropriate messagemethod from the menu Program Development. In the case that more than one robot have been constructed, a dilog frame appears in order to select the robot that the message will be sent to.

 

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 a robot, class, 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 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:
  1. We select Delete } Main Program from the menu Edit.
  2. In the dialog box Confirmation we press Yes.
Editing a class:

1.     We select Edit } Class from the menu Edit and the window with the cardsClass DeclarationandMethods Definitionappears 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:
  1. We select Edit } Robot 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 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 canat 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 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.     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.

 

*   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 } Class

Delete the declaration of the class and the definition of its methods.

 

Delete } Main Class

Delete the main program.

 

Edit } Class

Edit a class (and its methods) that has been declared by the user.

 

Edit } Robot

Edit a robot construction and initialization statement.

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.