Class-level Methods and Inheritance Part 2

Slides:



Advertisements
Similar presentations
CS320n –Visual Programming Class-level Methods and Inheritance – Part 1 Mike Scott (Slides 4-3-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger.
Advertisements

Class-level Methods Alice. World / Class Method World method A general method that may refer to multiple objects; not closely associated with any particular.
Class-level Methods and Inheritance Part 1 Alice.
Class-level Methods Chapter 6. Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class.
Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Class-level Methods and Inheritance MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
World-level Methods with Parameters Alice. Larger Programs As you become more skilled in writing programs, you will find that your programs quickly begin.
Parameters Section 8-8 Web Design. Objectives The student will: Understand what a parameter is Understand how to use a parameter in Alice Understand how.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Fall 2007ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Creating An Animation Program Alice Web Design Section 8-4.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Arrays and Array Visualization Alice. What is an array? An array is a collection of objects or information that is organized in a specific order. The.
Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.
Alice Tips and Techniques. Tips and Techniques I suggest you read the tips and techniques sections at the ends of the chapters. Tells you how to do things.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Writing Our Own Functions Alice. Functionality A function receives value(s), performs some computation on the value(s), and returns (sends back) a value.
What we will do today Learn about functions in Alice.
Creating An Animation Program Alice. Recall We began the animation creation process We introduced the concept of storyboard We will continue using the.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
World-level Classes Chapter 6 Part 2. Programs Grow Program code grows larger over time This makes it more difficult to read and process the code in our.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Parameters Alice. A beetle band Our task is to create an animation for a bug band as an advertisement for their next concert.
Parameters Alice. Overview The need for more flexible methods Passing a parameter to a method Demos Using the Alice interface to write code for a parameter.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Creating an Animation Program Alice. Step 1: Design Decide on the problem to be solved Design a solution We will use a storyboard design technique, commonly.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
1 Quiz Show Programming Terms. 2 Alice - 3D Virtual Programming Vocabulary Quiz Board Chapter 1 Chapter 2a Chapter 2b Chapter 3 Chapter 4 $100 $200 $300.
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Obj: to recognize built-in functions and expressions HW: Read Section 3.1 and do HW4 Edmodo article due Sunday at 8pm Edmodo feedback due 8pm 10/17 Do.
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Parameters Section 8-8 Web Design.
Functions Sec 51 Web Design.
Learn about functions in Alice
Arrays and Array Visualization
Chapter 3: Variables, Functions, Math, and Strings
Chapter 3: Variables, Functions, Math, and Strings
Functions Sec 8-11 Web Design.
World-level Methods with Parameters
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Parameters Alice.
CS320n –Visual Programming
Classes, Objects, and World-level Methods
Class-level Methods Alice.
Parameters and World-level methods
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Variables and Inheritance Part 1
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Parameters Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Class-level Methods and Inheritance
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Presentation transcript:

Class-level Methods and Inheritance Part 2 Alice

Guidelines To avoid potential misuse of class-level methods, follow these guidelines: Avoid references to other objects Avoid calls to world-level methods Play a sound only if the sound has been imported and saved out as part of the new class If these guidelines are not followed and an instance of the new class is added to another world, Alice will open an Error dialog box to tell you that something is wrong.

Bad Example 1

Bad Example 2

Problem What if you are convinced that you really want to write a class-level method where another object is involved? For example, a method to make the skater skate around another object-- in this scene, the penguin.

Solution A solution is to write a class-level method with an object parameter that allows you to pass in the specific object. cleverSkater.skateAround Parameter: whichObject Do in order Do together cleverSkater turn to face whichObject cleverSkater lift right leg cleverSkater move to whichObject cleverSkater turn around whichObject

Translating design into code Most of the skateAround storyboard design is straightforward and easy to code. The last two steps, however, require some thought: cleverSkater move to whichObject -- what distance should the cleverSkater move? cleverSkater turn around whichObject -- how do we tell cleverSkater to turn (in a circle) around another object?

Built-in Questions The built-in question, distance to can be used to determine the distance the skater must move.

Calling the question The instruction to move the skater to whichObject (penguin, in this example) would look like this: Unfortunately, the skater will collide with the penguin because the distance between two objects is measured center-to-center.

Expressions To avoid a collision, use a math operator to create an expression that adjusts the distance. Math operators in Alice: addition + subtraction  multiplication * division / Example:

asSeenBy To have the skater skate around another object, pass whichObject as an argument to the asSeenBy parameter in a turn instruction. For more details on asSeenBy, review Tips & Techniques 2.

Demo Demonstrate skateAround

Testing Each time you create a new class, test it: Add an instance of the new class to a new world. Write a short testing program to test each new method. Testing increases your confidence in the ability to reuse your code in other worlds.

Lab Lab 4-3 Chapter 4 Project