1 CSC 221: Computer Programming I Spring 2010 Objects and classes: a broad view  Scratch programming review  object-oriented design, software objects.

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

Create a Simple Game in Scratch
XP Tutorial 4 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Personalizing Your Windows Environment Tutorial 4.
COMPREHENSIVE Windows Tutorial 3 Personalizing Your Windows Environment.
Harry Potter Scratch Game
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 2 Stewart Blakeway FML 213
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Fall 2007ACS-1903 BlueJ Ron McFadyen Lab 1: Using BlueJ at UofW The purpose of this lab is to give you some experience with BlueJ. Over the course of the.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Digital Art in Scratch part 1 Barb Ericson Georgia Tech Oct 2010.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
GameMaker.  A lot of Different Definitions  Easier to Say What is NOT a Game  Movie is Not a Game  No Active Participation  Final Outcome is Fixed.
1 CSC 221: Computer Programming I Fall 2004 Objects and classes: a first pass  software objects, classes, object-oriented design  BlueJ IDE, compilation.
INTRODUCTION TO THE SCRATCH PROGRAMMING ENVIRONMENT.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Chapter 3 Working with Symbols and Interactivity.
Click your mouse for next slide Flash – Introduction and Startup Many times on websites you will see animations of various sorts Many of these are created.
Code Club Session 2 Dance Party. What will we learn ?  How to change the background  How to create animations  How to make objects talk to each other.
PowerPoint Basics (for Macs) 1. Before you start your project, you need: Completed project storyboard. Files with images, sound, or video already saved.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
IE 411/511: Visual Programming for Industrial Applications
Introduction to Programming with Java. Overview What are the tools we are using – What is Java? This is the language that you use to write your program.
Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Chapter 10 Fireworks: Part II The Web Warrior Guide to Web Design Technologies.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
OBJECTS AND CLASSES CITS1001. Concepts for this lecture class; object; instance method; parameter; signature data type multiple instances; state method.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
1 CSC 221: Computer Programming I Spring 2008 Objects and classes: a broad view  software objects, classes, object-oriented design  BlueJ IDE, compilation.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
Sequence Diagrams And Collaboration Diagrams HungNM.
1 CSC 222: Object-Oriented Programming Spring 2013 Objects and classes: a first pass  221 review  software objects, classes, object-oriented design 
Digital Art in Scratch part 1 Barb Ericson Georgia Tech May 2011.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Intro to GM 5.2 Edited 06/14/05 1 Introduction to GeoMedia 5.2 Before you can start on your school mapping project, you will need to become acquainted.
Image #1 Getting Started
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Computer Programming Modeling a Passive Solar Home.
4 weeks to heaven.  Basic computer architecture  Power-up  Starting up Windows  Mousing  Keyboard  windows  Finding and starting programs  Working.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
1 CSC 221: Computer Programming I Fall 2009 Objects and classes: a broad view  Scratch programming review  object-oriented design, software objects 
Scratch for Interactivity Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high x increasesx decreases.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
Computer Programming Modeling a Passive Solar Home.
CIS 205—Web Design & Development Flash Chapter 3 Working with Symbols and Interactivity.
Computer Programming with Scratch JAOIT 8. Scratch Scratch is a programming language that makes it easy to create your own interactive stories, animations,
Today We Will Review: Operating Systems (Windows) (week 3 & 4) Starting up MS Windows Desktop and its contents Functions of the desktop components Brain.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Introducing Scratch Learning resources for the implementation of the scenario
Using MIT Scratch for Programming and Control Programming 9.
Create a Halloween Computer Game in Scratch
Scratch for Interactivity
CSC 222: Object-Oriented Programming
CSC 222: Object-Oriented Programming
Introduction to.
Image #1 Getting Started
Creating a Simple Game in Scratch
CSC 221: Introduction to Programming Fall 2018
Presentation transcript:

1 CSC 221: Computer Programming I Spring 2010 Objects and classes: a broad view  Scratch programming review  object-oriented design, software objects  BlueJ IDE, compilation & execution, shapes example  method calls, parameters  data types, object state  object interaction, picture example  other examples: Die, SequenceGenerator

Scratch programming review programming concepts from Scratch simple actions/behaviors(e.g., move, turn, say, play-sound, next-costume) control repetition(e.g., forever, repeat) conditional execution(e.g., if, if-else, repeat-until) logic(e.g., =, >, <, and, or, not) arithmetic(e.g., +, -, *, /) sensing(e.g., touching?, mouse down?, key pressed?) variables(e.g., set, change-by) communication/coordination(e.g., broadcast, when-I-receive) 2

3 Object-oriented programming the object-oriented approach to programming:  solve problems by modeling real-world objects e.g., if designing a banking system, model clients, accounts, deposits, …  a program is a collection of interacting objects  in software, objects are created from classes the class describes the kind of object (its properties and behaviors) the objects represent individual instantiations of the class classes & objects in Scratch: class: cat, baseball, die, …(collections of sprite templates) object: sprite1, rollButton, …(can create or stamp out instances) properties/fields: size, coords, costume, …(can view on stage and above scripts) behaviors/methods: turn, move, think, …(can execute by clicking script or flag)

4 Class & object examples  the class encompasses all automobiles they all have common properties: wheels, engine, brakes, … they all have common behaviors: can sit in them, start them, accelerate, steer, …  each car object has its own specific characteristics and ways of producing behaviors my car is white & seats 7; the batmobile is black & seats 2 accelerating with V-6 is different than accelerating with jet engine REAL WORLD CLASS: automobiles REAL WORLD OBJECTS: my 2003 Buick Rendezvous, the batmobile, … class or object?  student  Creighton University  Morrison Stadium  shoe

5 Shape classes and objects a simpler, more abstract example involves shapes  class: circles what properties do all circles share? what behaviors do all circles exhibit?  objects: similarly, could define classes and object instances for other shapes  squares:  triangles:

6 BlueJ and software shapes we will start with a visual example in BlueJ: drawing shapes the BlueJ interactive development environment (IDE) is a tool for developing, visualizing, and debugging Java programs  BlueJ was developed by researchers at Deakin University (Australia), Maersk Institute (Denmark), and University of Kent (UK)  supported by Sun Microsystems, the developers of Java  note that BlueJ does NOT include a Java compiler/interpreter must install Sun’s Java SDK (software development kit); BlueJ connects to it BlueJ includes an editor, debugger, visualizer, documentation viewer, …

7 Starting up BlueJ to start up the BlueJ IDE, double-click on the BlueJ desktop icon to open an existing BlueJ project  click on the Project heading at the top left  from the resulting pull-down menu, select Open Project  browse to locate and select the project this opens the BlueJ main window  in order to create and execute a program, must first create or load a project  a project groups together all the files needed to produce a working program similar to a Scratch project

8 Creating a shapes project create a project named shapes on the Desktop  go to the class code directory (click on the link at the bottom of the syllabus)  right-click and save the following files to the Desktop/shapes folder: CanvasCircleSquareTriangle  note: new classes will not appear until you either 1.close & reopen the project, or 2.you explicitly "Add Class from File" from Edit menu classes are shown in a diagram  Canvas represents a painting area (i.e., a stage)  Circle, Square, and Triangle represent shapes  the arrows show that the shapes depend upon the Canvas class correspond to the sprite templates in Scratch

9 Editing and compiling classes you can view/edit a class definition by double-clicking on its box  this opens the associated file in the BlueJ editor (equivalent to the scripts that define a sprite’s behavior) before anything can be executed, the classes must be compiled  recall, the Java compiler translates Java source code into Java byte code  to compile all classes in a project, click on the Compile button (note: non-compiled classes are shaded, compiled classes are not) IMPORTANT: classes don’t act, objects do!  you can’t drive the class of all automobiles  but you can drive a particular instance of an automobile in order to draw a circle, must create a circle object  then, can specify properties of that instance (radius, color, position, …)

10 Example: creating a circle right-click on a class to see all the actions that can be applied  select new Circle() to create a new object  you will be prompted to specify a name for that object (circle1 by default) the new Circle object appears as a box at the bottom of the screen  note: classes and objects look different EXERCISE: create 2 circles, a square, and a triangle corresponds to creating or stamping out a copy of a sprite in Scratch

11 Applying object methods when the Circle object is created, it is automatically displayed in the Canvas window can select actions by right-clicking on an object icon  the actions that objects can perform are called methods EXERCISE: move your shapes around the change color & size PLAY! selecting a method corresponds to dragging the action block into the script window & clicking on it

12 Methods and parameters sometimes an action (i.e., method) requires information to do its job  the changeColor method requires a color (“red”, “green”, “black”, …)  the moveHorizontal method requires a number (# of pixels to move)  data values provided to a method are called parameters Java provides for different types of values  String is a sequence of characters, enclosed in double-quotes (e.g., “red”)  int is an integer value (e.g., 40)  double is a real value (e.g., )  char is a character value (e.g., ‘A’)  the parameter to changeColor is a String representing the new color  the parameter to moveHorizontal is an int representing the # of pixels to move recall: some blocks in Sratch required parameters (e.g., move & turn)

13 Objects and state recall that each object has properties and methods associated with it  when you create a Circle, it has an initial size, color, position, …  those values are stored internally as part of the object  as methods are called, the values may change  at any given point, the property values of an object define its state BlueJ enables you to inspect the state of an object  right-click on the object  select Inspect to see the values of object properties note: objects of the same class have the same properties, but may have different values corresponds to viewing the properties of a sprite on the stage or above the scripts in Scratch

14 IN-CLASS EXERCISE create objects and call the appropriate methods to produce a face  be creative – make it look interesting  what would you need to do in order to move the face vertically/horizontally?

15 The Face class now load the Face class from the Code directory  the Face class automates the drawing of the face – creating and positioning the head, eyes, and mouth  when the moveHorizontal and moveVertical methods are called on a Face object, all the components are moved together EXERCISE: view the source code of Face by double-clicking on its box EXERCISE: modify this class to automate your face picture corresponds to a script in Scratch

16 Class examples: Die & SequenceGenerator can define a Die class to model different (numeric) dice  properties shared by all dice: number of sides, number of times rolled  behaviors/methods shared by all dice: roll it, get # of sides, get # of rolls the roll method generates a random roll and returns it the return value is displayed by BlueJ in a Method Result window the SequenceGenerator class similarly returns a random string of letters  many interesting problems involve decisions based on random values  we can use an N-sided Die object to select between N alternatives Singer, PaperSheet, …