GreenFoot for Beginners (GFB)


GFB:   SOLD       




Substance:

  1. Starting the Application
  2. Creating Actors (Actro Classes)
  3. Creating Actor Environments (World Classes)
  4. Scenario Compilation
  5. Instantiating Actor Class into Object
  6. Interaction With Object Move()
  7. Interaction With Object Turn()
  8. Interaction Through Code Lines
  9. Simulation
  10. Evaluation and Conclusion

1. Starting the Application

The first thing that needs to be done to create a scenario/project from this application is as in the example below:

Case Study 1:

Create a scenario with the scenario name starting with your NIM followed by Project_1, for example: a student with NIM 12345, then the scenario name is 12345_Project_1


Creating Projects and Scenarios

  1. After the application is running, select the Scenario menu
  2. A drop down menu appears, then select New
  3. Then a new dialog window appears
  4. Name it according to your wishes (in this example following the Case Study).
  5. If you are sure, select Create, then you will be taken to the main window as follows;


Project Main Window

The page above shows many features that are not yet active, this is because we have not created the World class and Actor class, so there is not much we can do, therefore, the next step is:

2. Creating Actors (Actor Classes)

An actor represents someone or something (such as a device, another system) that interacts with the system. An actor may provide input information to the system and receive information from the system.

Classes are part of the scenario, which is divided into 2, namely World classes and Actor Classes.

To create an actor, the steps to be taken are as follows:


Creating an Actor

  1. Right click on the Actor icon
  2. Select New subclass
  3. Then a new window will appear with a display like the one below;


Class elephant as actor

  1. New class name, to give a name to the new class
  2. Image Categories, divide images based on their groups
  3. Library Images, displays several images based on their category
  4. Import form file, used if you want to add images other than those provided by Library Images.

Case Study 2:

Create an actor with the following conditions;

Students with NIM:

  • If the last digit 1 and the last 2 digits are odd, then create an actor with the class name ant
  • If the last digit 1 and the last 2 digits are even, then create an actor with the class name alligator.
  • If the last digit is 2 and the last 2 digits are odd, then create an actor with the class name bee.
  • If the last digit is 2 and the last 2 digits are even, then create an actor with the class name butterfly.
  • If the last digit is 3 and the last 2 digits are odd, then create an actor with the class name camel.
  • If the last digit is 3 and the last 2 digits are even, then create an actor with the class name dolphin.
  • If the final digit is 4 and the last 2 digits are odd, then create an actor with the class name elephant
  • If the last digit is 4 and the last 2 digits are even, then create an actor with the class name fish.
  • If the last digit is 5 and the last 2 digits are odd, then create an actor with the class name fly.
  • If the final digit is 5 and the last 2 digits are even, then create an actor with the class name frog
  • If the final digit is 6 and the last 2 digits are odd, then create an actor with the class name hedgehog
  • If the final digit is 6 and the last 2 digits are even, then create an actor with the class name ladybug
  • If the last digit is 7 and the last 2 digits are odd, then create an actor with the class name lobster.
  • If the last digit is 7 and the last 2 digits are even, then create an actor with the class name mouse.
  • If the last digit is 8 and the last 2 digits are odd, then create an actor with the class name lemur.
  • If the last digit is 8 and the last 2 digits are even, then create an actor with the class name lizard.
  • If the last digit is 9 and the last 2 digits are odd, then create an actor with the class name seahorse.
  • If the last digit is 9 and the last 2 digits are even, then create an actor with the class name seal.
  • If the last digit is 0 and the last 2 digits are odd, then create an actor with the class name turtle.
  • If the last digit is 0 and the last 2 digits are even, then create an actor with the class name spider.

Note: Use an image according to the class name!

3. Creating Actor Environments (World Classes)

Every object needs an environment, just as living things need a habitat to live, meaning an application needs an operating system to run. The steps to create World Classes are actually the same as when you create Actor Classes, because later you will also be shown a new window that is exactly the same as when creating an Actor, only the category you need to choose must be different from Actor, so it is no longer Animal but Backgrounds.

4. Scenario Compilation

After creating the Actor Class and World Class, you need to compile it so you can run your Scenario.


Scenario Compilation

Next you will be presented with the World window and the control features that are already active, as shown in the example below:


World Classes is now active

5. Instantiate Actor Class into Object

In standard Java, instantiating an object from a class is done with the following syntax:

[nama class] [nama object/variabel] = new [nama class]();

Contoh: Animal elephant = new Animal();

Meanwhile in Greenfoot it is done in this way;


Instantiating Actor Class into Object

6. Interaction With Object Move()

Interacting with objects created with the move() behavior/method, how to do it? see the explanation in the image below!


Interaction With Object Move()

7. Interaction With Object Turn()

Do the steps as above, only now try it with the void turn(int) method interaction, then fill in the parameter value with the number 5.

8. Interaction Through Code Lines


Interaction Through Code Lines


Greenfoot Code Console

Next, add the instructions below into the act(){} method block!

1\. move(5)
2\. turn(5)
3\. if(isAtEdge())
    {

      turn(5)

    }

4. Run your scenario using the Run button. See the results in the simulation video!

9. Simulation

https://youtu.be/L72moaad4y4

10. Evaluation and Conclusion

Question 1). Mention and explain the function of the control objects of each execution object in the Execution Controls area!

Answer 1).

  • Act: used to run scenarios manually (step by step) based on the overall program that has been created.
  • Run: used to run a scenario automatically based on the overall program that has been created.
  • Speed: used to set the speed when the scenario is run.
  • Reset: used to clear the appearance of actor objects in the world.

Question 2). Observe and explain what happens in the scenario before and after compilation!

Answer 2).

  • Before compiling, the world page is not displayed.
  • Once compiled, the world page is available or displayed so that object or actor scenarios can be created.

Question 3). Fill in the move() method dialog window with the integer value 10, observe and explain what happens!

Answer 3).

When the move() method dialog window is filled with the integer value 10, the object/actor will move slightly to the right by 10 cells (where each cell is 1x1 pixel in size).

Question 4). Fill in the dialog window of the turn() method with the integer value 5, observe and explain what happens!

Answer 4).

When the turn() method dialog window is filled with the integer value 5, the object/actor will rotate slightly to the right by 5 cells (where each cell is 1x1 pixel in size).

Question 5). State the function of the control objects from the scenario as shown in the image below!

Answer 5).

  • Act: used to run scenarios manually (step by step) based on the overall program that has been created.
  • Run: used to run a scenario automatically based on the overall program that has been created.
  • Speed: used to set the speed when the scenario is run.
  • Reset: used to clear the appearance of actor objects in the world.

Question 6). What things did you get from the practice you did related to the Object Oriented Programming paradigm that you have studied so far?

Answer 6).

Based on the results of the practicum that I did, what I obtained based on the PBO paradigm is that an object reflects a class, so the number of classes can be determined by the number of objects and in its implementation a method, function or attribute is used to create the character of each object.


Post a Comment

Previous Next

نموذج الاتصال