Monkey See Monkey Do Important Turn on Javalike

  • Slides: 15
Download presentation
Monkey See, Monkey Do

Monkey See, Monkey Do

Important Turn on Java-like syntax option in Alice, if is not on already.

Important Turn on Java-like syntax option in Alice, if is not on already.

Revision - Objects • Our world is made up of objects • These objects

Revision - Objects • Our world is made up of objects • These objects are computer models of real world objects • They have properties (variables) that define the state of that object • They have behaviours they can act out • These behaviours are a list of instructions or code • To manipulate our objects, we must manipulate an object’s variables or have it carry out actions.

Alice Objects • All Alice objects are 3 D models that are visible in

Alice Objects • All Alice objects are 3 D models that are visible in your World • Most Alice methods/behaviours are animations that you wish these models to carry out • You can manipulate the starting positions of objects by mouse • Animate characters by writing and calling methods

Alice Objects • Alice objects come with many default variables and methods – default

Alice Objects • Alice objects come with many default variables and methods – default methods cannot be edited • Alice provides a number of default boolean expressions - called questions • Alice objects can be made up of a number of sub-objects. These can be manipulated independantly

Revision - Methods • A method is a block of code (list of instructions)

Revision - Methods • A method is a block of code (list of instructions) • By default, the code is executed one line at a time • We can change this using execution control structures • Methods can have parameters

Alice Methods • Alice methods also contain a block of code • Code is

Alice Methods • Alice methods also contain a block of code • Code is written by dragging tags from one location and dropping in another • We can create temporary variables for use during method execution • We can define paramters for our method’s execution

Revision – IF/ELSE & boolean statements • IF statements allow our computer to make

Revision – IF/ELSE & boolean statements • IF statements allow our computer to make a choice • We use boolean statements or questions • Outcome dictates which block of code executes

Alice IF statements • Drag the IF tag from the top of method editing

Alice IF statements • Drag the IF tag from the top of method editing window • Drag in a question • Drag in code to fill in the other two outcomes

Revision – loop • A loop statement loops a number of times • The

Revision – loop • A loop statement loops a number of times • The code is repeatadly executed

Alice loop • Drag the loop tag from the top of method editing window

Alice loop • Drag the loop tag from the top of method editing window • Choose how many times you want the code to execute • Drag in code to fill in the other two outcomes

Revision – While • While statements loop until the testing condition is false •

Revision – While • While statements loop until the testing condition is false • This condition is tested prior to the next loop executing

Alice While loop • • Drag the while tag into the code area Drag

Alice While loop • • Drag the while tag into the code area Drag in a question Drag in code to fill in the while loop Make sure while loop ends at some stage

Revision – Parrallel • Normal execution is one line at a time • By

Revision – Parrallel • Normal execution is one line at a time • By using the do together command, we can execute multiple lines at once In Java, multiple execution of code is possible – although somewhat difficultl

Dot notation • If you have correctly set Java-like syntax, you will see dot

Dot notation • If you have correctly set Java-like syntax, you will see dot notation • Monkey. head is the Monkey object’s head object • Monkey. head. color is the Monkey object’s head object’s color • This notation allows the computer to work out who owns what