Getting Started with Java Using Alice. 1 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Similar documents
Table of Contents. Page 2 ebook created with Orion PDF Author orion.aidaluu.com. What is Orion Label Maker?

Finch Robot: snap level 4

Reference Guide Playful Invention Company

Scratch Lesson Plan. Part One: Structure. Part Two: Movement

Workbook. Version 3. Created by G. Mullin and D. Carty

The Leader in Me Chari Distler

Sketch Out the Design

Pet Notes and Appointment Notes

6.14(a) - How to Run CAT Reports Record Errors Report

Lab 7. Evolution Lab. Name: General Introduction:

Lab 10: Color Sort Turtles not yet sorted by color

Biol 160: Lab 7. Modeling Evolution

Cow Exercise 1 Answer Key

November Final Report. Communications Comparison. With Florida Climate Institute. Written by Nicole Lytwyn PIE2012/13-04B

Econometric Analysis Dr. Sobel

The Lost Treasures of Giza

PNCC Dogs Online. Customer Transactions Manual

CS108L Computer Science for All Module 7: Algorithms

Getting Started! Searching for dog of a specific breed:

PNCC Dogs Online. Customer Transactions Manual

PENNVET BEHAVIOR APP Pet Owner Instructions

CAT Paid vs. CAT Unpaid November 2012

Math Skill Builders Grades 2-3

KB Record Errors Report

ENTRY CLERK MANUAL FOR THE ENTRYCLERK.CFA.ORG WEB APPLICATION. Page 1

Lab 5: Bumper Turtles

Texel Sheep Society. Basco Interface Guide. Contents

Hello Scratch! by Gabriel Ford, Sadie Ford, and Melissa Ford. Sample Chapter 3. Copyright 2018 Manning Publications

Activity 1: Changes in beak size populations in low precipitation

Call of the Wild. Investigating Predator/Prey Relationships

For ADAA users, you will see a page similar to the one shown below:

Building Concepts: Mean as Fair Share

Army Community Recreation Reports Online (ACRRO) 2.0 Bulk Buy Requests Quick Reference Help Guide

Scratch Jigsaw Method Feelings and Variables

Questions and answers for exhibitors entering shows using TOES

Lesson 1.3. One Way Use compatible numbers. Estimate Sums Essential Question How can you use compatible numbers and rounding to estimate sums?

Coding with Scratch Popping balloons

SEVENTH'ANNUAL'JUILFS'CONTEST' SPRING'2015' ' '

Lab 6: Energizer Turtles

Guidance Notes on the Antimicrobial Companion Audit Tool for the Antimicrobial Prescribing Quality Indicators 2017/18

~~~***~~~ A Book For Young Programmers On Scratch. ~~~***~~~

Coding with Scratch - First Steps

Home - Returns you to the home page where you can access the main menu. About - Welcome to Dane Quest, defines purpose and basic overview

CONNECTION TO LITERATURE

RUBBER NINJAS MODDING TUTORIAL

English Language Arts Test Book 2

OBJECTIVE: Students work as a class to graph, and make predictions using chicken weight data.

INTRODUCTION TO VISUAL HEALTH ASSESSMENTS

Color On, Color Off Multidisciplinary Classroom Activities

The City School. Learn Create Program

Challenge Math & Summer Activities

Geometry from Scratch

SMARTKITTY SELFCLEANING LITTER BOX

Manual Compustam-Cloud

INFO 1103 Homework Project 2

W360 Multifunction Tabber System Operator Guide

Biology Meets Math. Predator-Prey Relationships in Belowground Ecosystems. US Department of Homeland Security

SARG Guide Surrey Amphibian and Reptile Group. SARG Reptile Surveyor s Guide Using SARGWEB. April 2012 Version 1.0. Steve Langham

Help the Scratch mascot avoid the space junk and return safely back to Earth! Start a new Scratch project. You can find the online Scratch editor at

INFO 1103 Homework Project 1

Solving Problems Part 2 - Addition and Subtraction

Overview of Online Record Keeping

Life Under Your Feet: Field Research on Box Turtles

Dasher Web Service USER/DEVELOPER DOCUMENTATION June 2010 Version 1.1

Unit 4, Lesson 7: One Hundred Percent

by Jennifer Oxley and Billy Aronson

Finch Robot: snap levels 1-3

DOWNLOAD OR READ : CAT OWNERS PROBLEM SOLVER PDF EBOOK EPUB MOBI

Quick Setup Guide Model 5134G

Bart Walter sculptor C OLL E C T OR S CATALOGUE Selected Works

Scratch. To do this, you re going to need to have Scratch!

6. 1 Leaping Lizards!

Mendelian Genetics Using Drosophila melanogaster Biology 12, Investigation 1

Be Doggone Smart at Work

Writing Simple Procedures Drawing a Pentagon Copying a Procedure Commanding PenUp and PenDown Drawing a Broken Line...

WHAT TECHNOLOGY DO RESEARCHERS USE TO STUDY AFRICAN CATS?

Fruit Fly Exercise 2 - Level 2

Nathan A. Thompson, Ph.D. Adjunct Faculty, University of Cincinnati Vice President, Assessment Systems Corporation

USING FARMAX LITE. Upper navigation pane showing objects. Lower navigation pane showing tasks to be performed on objects

Chapter 16: Evolution Lizard Evolution Virtual Lab Honors Biology. Name: Block: Introduction


Grade Level: 2-8; others with modification

Pet Care Pluses Adapted by Amelia Saris

Genetics Lab #4: Review of Mendelian Genetics

Army Community Recreation Reports Online (ACRRO) 2.0 Bulk Buy Requests Quick Reference Help Guide

Check the box after reviewing with your staff. DNA Collection Kit (Cheek Swab) Mailing a DNA Cheek Swab to BioPet. Waste Sample Collection

Dog Agility Starter Kit

Teacher Workbooks. Language Arts Series Internet Reading Comprehension Oceans Theme, Vol. 1

Supporting document Antibiotics monitoring Short database instructions for veterinarians

Grade 5, Prompt for Opinion Writing Common Core Standard W.CCR.1

Turtle Ballet: Simulating Parallel Turtles in a Nonparallel LOGO Version. Erich Neuwirth

Saint Bernards. and Other Working Dogs. by Holly Schroeder illustrated by Troy Howell. Scott Foresman Reading Street 2.2.5

Adélie Penguin Bird Count

The Case for Dog Kennels on Titanic s Boat Deck

Applications KARL MALONE JOHN STOCKTON. a. What fraction benchmark is near the number of free throws made by each player?

Quality ID #352: Total Knee Replacement: Preoperative Antibiotic Infusion with Proximal Tourniquet National Quality Strategy Domain: Patient Safety

Timing is Everything By Deborah Palman

The purchaser may copy the software for backup purposes. Unauthorized distribution of the software will not be supported.

$2.85 $4.10 $1.00 $25.00 $2.25 $2.25 4X4 CUSTOM QUOTE: $55.00 PLUS $1.00 PER LINE 8X10 CUSTOM QUOTE: $75.00 PLUS $1.00 PER LINE

Scratch Programming Lesson One: Create an Scratch Animation

Transcription:

Getting Started with Java Using Alice Use Functions 1 Copyright 2013, Oracle and/or its affiliates. All rights

Objectives This lesson covers the following objectives: Use functions to control movement based on a return value 2 Copyright 2013, Oracle and/or its affiliates. All rights

Functions Functions: Are used to ask questions about properties of an object. Are similar il to procedures except that t they return a value of a particular type. Can be used to compute a value. Functions answer questions about an object, such as its height, width, depth, and even its distance to another object. 3 Copyright 2013, Oracle and/or its affiliates. All rights

Functions Precisely Answer Questions Functions provide precise answers to questions, such as: What is the distance between the helicopter and the ground? What is the height of the cat? What is the width of the owl? A boolean function returns either a true or false value. For example, if the isfacing function is called to determine if the person object is facing the tree object, a true or false value will be returned. 4 Copyright 2013, Oracle and/or its affiliates. All rights

Functions Tab The Functions tab is in the methods panel. Select the object from the Instance menu, and then view its functions. 5 Copyright 2013, Oracle and/or its affiliates. All rights

Functions Solve Distance Problems Suppose we want to move the lioness directly to the rock without having to manually determine, through trial and error, the distance between the lion and the rock. We could guess the distance by specifying a placeholder value and testing the movement until we get close to the desired end result, but a more efficient way is to use a function to determine the exact distance to move. 6 Copyright 2013, Oracle and/or its affiliates. All rights

Use getdistanceto Function Use the getdistanceto function in the move procedure to solve this distance problem. 7 Copyright 2013, Oracle and/or its affiliates. All rights

Steps to Use the getdistanceto Function 1. Determine the moving object and target object. 2. In the Code editor, select the moving object from the Instance menu. 3. Drag the move procedure into the Code editor. 4. Select the direction and a placeholder argument for distance (the distance argument will be modified in the next step). 5. From the Functions tab, drag the getdistanceto tile onto the highlighted hli ht distance value. 6. Select the target object. 8 Copyright 2013, Oracle and/or its affiliates. All rights

Test the Function Click the Run button to test the programming statement. In the example below, the lioness moves to the center of the rock at run-time. This could be read out loud as "determine the distance from the center of the lioness to the center of the boulder and then move the lioness forward that amount." 9 Copyright 2013, Oracle and/or its affiliates. All rights

Test the Function The lioness moves to the middle of the rock. This is because the getdistanceto function calculates the distance between the centers of both objects. The function calculated the distance from the center of the lioness to the center of the rock, and moved the object using that value. 10 Copyright 2013, Oracle and/or its affiliates. All rights

Avoid Collisions You can enhance function calls using the math operators (+) addition, (-) subtraction, (*) multiplication, and (/) division. For example, you can reduce the distance an object will move to avoid a collision. 11 Copyright 2013, Oracle and/or its affiliates. All rights

Using Math Operators A function determines the distance between the lioness and the rock. To reduce the value returned by the getdistance function, the subtraction operator subtracts a specified value. The specified value is determined by calling the getwidth function and dividing that value in half. Lioness Rock X = Get distance from lioness to rock Y = Get width of rock Z = X (Y / 2) 12 Copyright 2013, Oracle and/or its affiliates. All rights

Examine the Math Calculation Let's examine the math calculation Z = X - (Y / 2): Z represents the total distance the lioness will move. X represents the distance between the lioness and rock. Y represents the width of the rock. Y / 2 represents the width of the rock divided by 2. ( ) represent the order of precedence. Lioness Rock X = Get distance from lioness to rock Y = Get width of rock 13 Copyright 2013, Oracle and/or its affiliates. All rights

Math Operator Tip Why did we divide the width of the rock in our calculation? Because we want the animation to appear as though h the lioness is moving to the very edge of the rock. If we used the entire width of the rock, the lioness would stop further from the rock than desired. Lioness Rock X = Get distance from lioness to rock Y = Get width of rock 14 Copyright 2013, Oracle and/or its affiliates. All rights

Steps to Use Math Operator to Avoid Collision 1. Click the outer arrow next to the function argument. 2. Select Math. 3. Select the getdistanceto subtraction option. 4. Select the distance amount. 5. Run the animation to test how the object moves at run-time. 15 Copyright 2013, Oracle and/or its affiliates. All rights

Understanding the Math Menus Example 1 The following image displays the math operators (+ - * / ) requiring one or two arguments. Each option will provide one or two cascading menus to specify the argument values. 16 Copyright 2013, Oracle and/or its affiliates. All rights

Understanding the Math Menus Example 2 The following image displays an (+) addition operator requiring a single argument. The following image displays math operators requiring two arguments. Remember, you can select placeholder values for the arguments. Placeholder values can always be edited. 17 Copyright 2013, Oracle and/or its affiliates. All rights

Remove Object s Depth from Function Another precise way to avoid collisions is to remove the depth (length) of the moving object from the function. In the example below, the lioness will move the distance to the rock, minus the depth of the lioness. Lion Rock Distance from lioness to rock Lioness depth 18 Copyright 2013, Oracle and/or its affiliates. All rights

Depth is Measured from Object s Center When a distance value is calculated, it is measured from one object's center to another object's center. The same is true for math calculations. When the depth of the lioness is subtracted from the rock, it is actually subtracted from the center of the rock. Lioness Rock Distance from lioness to rock Lioness depth 19 Copyright 2013, Oracle and/or its affiliates. All rights

Steps to Remove Depth from Function 1. In the Functions tab, drag the moving object s getdepth function onto the highlighted distance value. 2. Run the animation to test how the object moves at run-time. Adjust with additional math calculations if necessary. 20 Copyright 2013, Oracle and/or its affiliates. All rights

Summary In this lesson, you should have learned how to: Use functions to control movement based on a return value 21 Copyright 2013, Oracle and/or its affiliates. All rights