Programming Clara Chapter 1

PreferableOrphism avatar
PreferableOrphism
·
·
Download

Start Quiz

Study Flashcards

16 Questions

What does the putLeaf() command do?

Puts one leaf at Clara's current position

What is the function of the turnLeft() command?

Clara turns 90 degrees to the left

What is the purpose of the treeRight() command?

Checks if there is a tree on Clara's right

What happens when the stop() command is executed?

Clara terminates the execution of the program

What type of commands are treeFront(), treeRight(), onLeaf(), and mushroomFront()?

Sensors

What is the primary function of sensors in Clara's World?

To sense aspects of the state of Clara's World

What can be created in Java to illustrate new commands?

A new method

In which direction does Clara turn when the turnRight() command is executed?

90 degrees to the right

What do actuators, such as move() or turnLeft(), do in Clara's World?

Instruct Clara to perform a particular action

What happens when the removeLeaf() command is executed?

Clara removes a leaf at her current position

What does the treeFront() method return if there is a tree immediately in front of Clara?

The value true

What is the purpose of the stop() command in Clara's World?

To terminate the execution of the act() method

In which method can the stop() command not be used?

run() method

What is the main difference between the act() and run() methods?

The act() method executes the code repeatedly, while the run() method executes the code only once

Why do we use the act() method instead of the run() method in this chapter?

Because the act() method executes the code repeatedly, while the run() method executes the code only once

What happens when the code is executed inside the run() method?

The code is executed once, and then the program terminates

Study Notes

Clara's Commands

  • Clara can perform the following commands: move(), turnRight(), putLeaf(), and removeLeaf()
    • move(): Clara moves one step forward in the direction she is currently facing
    • turnRight(): Clara turns 90 degrees to the right
    • putLeaf(): Clara puts one leaf at her current position
    • removeLeaf(): Clara removes a leaf at her current position

New Commands

  • Clara has gained new skills and commands, including:
    • turnLeft(): Clara turns 90 degrees to the left
    • treeFront(): Clara checks if there is a tree one cell in front
    • treeRight(): Clara checks if there is a tree on her right
    • onLeaf(): Clara checks if there is a leaf at her current position
    • mushroomFront(): Clara checks if there is a mushroom one cell in front
    • stop():Terminate the execution of the program

Flow of Control and Sensors

  • The turnLeft() command has the same functionality as the corresponding method created in Chapter 1
  • The four new commands (treeFront(), treeRight(), onLeaf(), and mushroomFront()) are sensors that do not change the state of Clara's World, but help sense some aspects of this state
  • These sensor commands return a value in the form of true or false in relation to a particular aspect of Clara's World

The Difference between act() and run()

  • Code written inside the run() method is executed once and then the program terminates
  • Code written inside the act() method will be executed repeatedly
  • The stop() command only works inside the act() method and will not work inside the run() method

Learn about Clara's commands such as move, turnRight, putLeaf, and removeLeaf in this introductory chapter. Clara will solve more difficult and interesting problems as the chapters progress.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser