Lecture 4: Finishing 4.2 and onto 4.3 What have you learned so far? To control a computer by designing and writing a program – Creating animations/movies.

Slides:



Advertisements
Similar presentations
Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.
Advertisements

INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
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.
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.
Chapter 4.3 Class level methods (versus previous world-level methods)
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Chapter 9.1: Lists Lists are often called by another name in other programming languages – arrays.
Fall 2007ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Alice Variables Pepper. Set to Java look Edit / preferences restart.
Programming in Alice Chapter 2 Part 2. Events Editor Identifies what method is executed (run) when the “Play” button is hit 2.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts.
Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Methods Tutorial: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 9, 2008.
METHODS!.  A method is a sequence of instructions or behaviors that will be carried out when requested.  You can use them to create new methods so that.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Hello AP Computer Science!. What are some of the things that you have used computers for?
Chapter 6: (Expressions,) Functions, and If/Else First we had animations – They “ran”/played the same way every time. – Neat, but a bit boring Then we.
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.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Making a Timer in Alice.
Lecture 5: Finishing 4.3 and onto 5.1 Preparing for the Midterm: Written Explanations Technology and Society Assignment (5% - 3 in term) – How does 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.
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Poses Tutorial Alex Boldt Under the direction of Professor Susan Rodger Duke University July 2015.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Alice: A Visual Introduction to Programming Chapter 1 Part 2.
Now that the kangaroo and the turtle have raced, let's make a method for the kangaroo to hop back to the turtle and challenge him to a race again. Click.
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
Lecture 3: Chapter 4.1 and 4.2 Discussion groups: Very impressed! – Excellent job by class-wide discussion contributors Learning Goal: Technical analysis.
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.
Functions Alice.
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
Flow Control: boolean expressions, “if” selection statements (Alice In Action, Ch 4) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
CompSci 4 Chap 4 Sec 1 Sept 15, 2005 Prof. Susan Rodger.
Creating a Historical Tour in Alice By Jenna Hayes May 2010.
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
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.
Methods (part 2) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS 120 Lecture 03 4 September 2012.
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.
Chapter 5 Interaction: Events and Event Handling.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Lesson 8C Animation and Events. Step 3: Animation Drag it into the method and have him say “let her go!” Click on the knight in the object tree and scroll.
Chapter 2: Programming in Alice
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Lecture Wed Week 7 Midterm grades on gradesource – Graded out of 26 (free point) – Question 1 confusing – everyone gets full points – Solutions posted.
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.
Alice Development Environment. Which area contains our “program” (set of instructions)? D AB C.
Class-level Methods Alice.
Alice Variables Pepper.
Introduction to Object-Oriented Programming in Alice
Using Alice This is an introduction to Alice..
Classes / Objects / Methods
Class-level Methods and Inheritance
Presentation transcript:

Lecture 4: Finishing 4.2 and onto 4.3 What have you learned so far? To control a computer by designing and writing a program – Creating animations/movies of your own choosing – With complex manipulations of objects using methods and variations in control (doTogether, doInorder) Developed skills in managing complexity in working with data on a computer – Abstraction by “breaking into pieces” Work on them independently and then put back together It may not seem like it, but you are building up valuable skills. I’ll give you text to put on your resume to help you describe it to employers!

Before we begin A.I was able to do homework for section 4.3 B.I was able to read section 4.3 C.I was able to skim section 4.3 D.I haven’t looked at section 4.3

Next Class Homework Chapter 4.3 (if you didn’t do it) Chapter 5.1 Homework Overview due: – Week 4 Monday: 5.2 and 6.1 – Week 4 Wed: 6.2 up to 188 – Week 5 Monday: Rest of 6.2 – Week 5 Wednesday: 7.1

In the World.solo method you created (with the beetles example), what type was the bandMember parameter? A.Boolean B.Number C.Object D.Other-> String E.ringoBeetle

Which of the following is the best definition of a class-level method? A.A method that controls an ice-skater B.A method that belongs to a particular object C.A method that takes parameters to control how it works D.A method that you need to be sure to save in order to be able to use it in the future

The somewhat complex steps of having a skater spin around were managed by what technique: A.Use of parameters to control the action B.Stepwise-refinement to create multiple levels of methods C.Class-level methods to support development of a new cleverSkater class D.Use of primitive methods pre-built into the Alice software

Academic Integrity and Social Responsibility Computer “programs” bring new complexities to academic integrity – There’s a lot of programs at alice.org I am responsible to – You – that your effort be rewarded – Your fellow students – their accomplishments have value Social Responsibility in a new situation (4 items) – Please don’t talk, murmur, mumble with others in group during Individual vote Class-wide discussion – Only FAIR to others that they have a supportive learning environment It’s a large room, it adds up

Just vocabulary: Parameters Always come “after” the method name on a tile

Alice: It’s REALLY close to Java (and most every programming language today) public class Demo { public static void main (String[] args) { World w = new World("Chapter04Example"); //x, y, and z coordinates) Skater iceSkater = new Skater(w, 100, 200, 0); iceskater.move("forward",.5, 2); //where 0 is forward, 1: backward, 2:left,etc. //iceskater.move(0,.5, 2); }

What does this do?

Which best describes what happens when my First Method is run? A.The helicopter moves down to the rabbit’s location B.The rabbit moves up to the helicopter’s location C.The helicopter and the rabbit move to meet each other (halfway between) D.I don’t know

More parameters: Demo: Let’s make fish fly… Preview: – We have a fly method (no parameters) which makes a fish jump out of the water.5 meters (moving forward.3 meters on the way up and another.3 meters on the way down) Maria would like to make it more flexible by parameterizing it to control height and distance – Take a look at what she’s done and see if it looks ok!

Any comments for Maria?

A.No, but you could make it better if you include a speed parameter B.No, it’s perfect as it is C.Yes, you have created the wrong parameters D.Yes, you have incorrectly used a parameter

Chapter 4.3 Class level methods (versus previous world-level methods) Define actions that inherently belong to a certain class of object – Dogs can “beg” – Skaters can “spin” – Penguins can “bellySlide” To create them you – click on an object of that type – Click on create method in the details pane (lower left) – After you write the method, you may want to save this out as a “new” class with your augmented abilities. Change name of object, right click and click save as – creates an.a2c file – a new Alice class file

World-level methods: – Belong to no “one specific” object (or class or objects) [Hint: starts with World.] Any objects, information you need to modify how it works should be passed as a parameter Class-level methods: – Are actions that belong to a specific “class” of objects [Hint: starts with an object name]

Which of the following would not be a good class level method (for some given class) A.Party B.Swim C.changeColor D.lineUpWith E.layDown *DISCUSSION: What possible parameters would you want to use with these methods?

Making our own class level method and creating a customized class Demo: Making a class level method for the spiderRobot class to allow any spiderRobot to say Hello to an Alien – Click on spiderRobot before clicking on make new method This makes it a class level method, not world level – Drag in the code to have him face the alien and then say hello – If we add another spiderRobot – he can’t say Hello, so save off that class as talkativeSpiderRobot Be sure to save it in the Gallery! Create 2 of those objects

How to parameterize a method In what ways would we want to be able to control/vary what this method does so that – We can re-use it in more situations – Does it make sense that someone would WANT to be able to control this method’s actions 2 Examples: – Next 6 slides: sayHelloToAlien -> sayTo A class-level method of spiderRobot – Next 4 slides: jumpOnto method A class-level method of chicken

If I want a spiderRobot class method which will have him say hello to anything (object) A.Create a method that is a class method of the object you want him to say hello to (e.g. alien) B.Create a method which takes one parameter: which object to turn to face C.Create a method which takes one parameter: a direction in which to face D.Create method that takes two parameters: the spiderRobot and the object it should turn to face E.I don’t know

Demo: How do we do that? Modify method name to sayHelloTo Create a parameter which will control what Object we want to greet Modify the class-level method to turnToFace the parameter object TEST! – Ah! What’s this null thing? Change the calling location in myFirstMethod to indicate which Object we want to have the robot face

What would the method header for a sayTo method look like Most importantly, what’s wrong with the other options!

Which of these would be the right method body?

Demo: How do we do that? (if time) Rename the method from sayHelloTo to sayTo Add a new parameter named whatToSay – It doesn’t matter if this is the first or second parameter to the sayTo method Modify the method body (definition) to make whatToSay be the parameter to the talkativeSpiderRobot.say method In myFirstMethod, where you call the sayTo method, change the whatToSay parameter to be whatever you want the robot to say TEST!

Suppose we have the following world with 2 objects of the talkativeSpiderRobot class What code will make this happen?

Which method call will make this happen? C) Both of those method calls do that same thing