Variables and Inheritance Part 1

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 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.
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Arrays and Array Visualization
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
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.
Making a Timer in Alice.
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
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.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Variables and Inheritance A More Complex Example Alice.
1 Chapter 12: Form Builder Objects and Flexible Code.
Functions Alice.
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Can I get your number? By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Variables and Functions Alice. Naming is Important If you get a new pet one of the first things you do is name it Gives you a way to refer to the new.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
Programming: Simple Control Structures
Ready, SET, go! By Melissa Dalis Professor Susan Rodger Duke University July 2011.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Obj: Programming: Simple Control Structures HW: Read section 3 – 2 AC3 D2 Do Now: 1.Log on to Alice. Open the file firstEncounter.a2w located in the folder.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Parameters Alice. A beetle band Our task is to create an animation for a bug band as an advertisement for their next concert.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
CompSci 4 Chap 10 November 4, 2010 Prof. Susan Rodger.
CompSci 4 Chap 10 Nov 22, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
PaintPictureBoxDemo Refers to the PaintPictureBoxDemo Visual Basic Program Included With The Lecture.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Variables and Inheritance Part 1 Alice. Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated),
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.
Variables.
Arrays and Array Visualization
Variables and Inheritance Part 2
Making a Timer This is an modification of the July 2008 timer tutorial by Jenna Hayes By Natalie Huffman Under the direction of Susan Rodger Duke University.
Programming: Simple Control Structures
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
Repetition: Definite Loops
Programming: Simple Control Structures
Programming: Simple Control Structures
Repetition: Definite Loops
Programming: Simple Control Structures
Repetition: Definite Loops
Variables and Inheritance Part 1
Programming: Simple Control Structures
The Web Wizard’s Guide To JavaScript
Programming: Simple Control Structures
Class-level Methods and Inheritance
under the direction of Professor Susan Rodger
Variables and Inheritance A More Complex Example
Presentation transcript:

Variables and Inheritance Part 1 Alice

Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated), it receives its own set of properties.

State Each property stores information about the object. Examples: vehicle isShowing The set of information about the object is called the state of the object.

State Change Instructions in our program code generally cause a change in a property value -- a state change. For example, a set instruction can be used to change the color of an object.

Class-level Variables New variables can be added to the properties list of an object. The new variable is class-level The value of the variable can be changed We say the variable is mutable. This extends the capability of an object to track state changes.

Example Game programs often make use of a timer – some mechanism to keep track of the time remaining in the game. We will construct a timer. First, add a 3D text object to the world. Any string of digits could be used. We arbitrarily chose "0.0"

Creating a new variable Select the timer object and then create a new variable named timeLeft. The isOn variable is declared to be a Number type. The value is 0 (the game hasn't begun, as yet).

Start the timer At the start of the game, the timer's timeLeft variable must be initialized to the amount of time allowed for playing the game. (This example uses seconds, but minutes would work just as well.) Storyboard for a method to initialize the timeLeft variable: initialize parameter: amountOfTime timeLeft is set to a value specified by amountOfTime

Counting down In this example, the timer will count down to 0 (no seconds left on the clock). Storyboard for a countDown method: countDown Do in order While timeLeft is greater than 0 update the 3D text to show the remaining number of seconds decrease timeLeft by 1 update the 3D text to display 0 seconds Note: The last instruction updates the 3D text display after the While loop ends .

class-level function To coordinate the game with the timer's countdown, write a function that returns the value of the timeLeft variable.

Demo Ch10Lec1aTimer Concepts illustrated in this example The value in a variable can be used in a conditional expression to control a loop. The value of timeLeft is compared to 0. The value in a variable can be changed at runtime. The value of timeLeft is decreased by 1 each time through the While loop. A number can be displayed as a text string by calling a built-in conversion function (as a string).

Save out Save out the timer as a new class. Rename the object (we used timerDown) Right-click on the object name and select save object…

Inheritance If the object (with its new variable) is saved out and given a new name, a new class is created. This is an example of inheritance. The new class inherits all the properties and methods (move, turn, roll, etc.) of the original class. Also, the new class has the newly declared variable and an extended capability to track state changes.

Import Now you can add an instance of the newly created class to a new world.

Assignment Read Chapter 10 Section 1, up to page 257.