1 CSC 221: Computer Programming I Fall 2009 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
Harry Potter Scratch Game
REVIEW FOR SOME WELCOME TO THE COMPUTER!. WHY ARE COMPUTERS IMPORTANT?
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.
Civil 114 Civil Engineering Drawing AutoCAD
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
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.
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.
A First Program Using C#
Inserting Pictures and Symbols in PowerPoint There are many ways to insert pictures – these are the most common methods Copy and Paste Copy and paste is.
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.
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
1 CSC 221: Computer Programming I Spring 2010 Objects and classes: a broad view  Scratch programming review  object-oriented design, software objects.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
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.
Art 321 Lecture 7 Dr. J. Parker. Programming In order to ‘make things happen’ on a computer, you really have to program it. Programming is not hard and.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
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.
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.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Image #1 Getting Started
Using This PowerPoint This PowerPoint presentation assumes your Computer Science teacher has provided you with the InstallingJava folder, which contains.
Scratch Another computer programming language Developed by MIT in 2003
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Computer Programming Modeling a Passive Solar Home.
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,
 SCRATCH is a new programming language that lets you create your own interactive stories, animations, games, music, and art.
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,
Alice in Action with Java Chapter 1 Getting Started with Alice.
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.
Functions / Blocks.
Create a Halloween Computer Game in Scratch
Scratch for Interactivity
CSC 222: Object-Oriented Programming
CSC 222: Object-Oriented Programming
Introduction to.
Java Applets.
Inserting Pictures and Symbols in Word documents
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 Fall 2009 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 Loading the shapes project BlueJ comes with a collection of example projects  copy C:\Program Files\BlueJ\examples to the desktop  click on the Project heading and select Open Project  browse to select Desktop  examples  shapes when a project loads, its classes are shown in a diagram  here, there are 4 classes  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 can cause objects to act by right-clicking on the object box, then selecting the action  the actions that objects can perform are called methods  here, void makeVisible() opens a Canvas in which the shape is displayed EXERCISE: make the other shapes visible EXERCISE: select other methods to change the color and size of objects EXERCISE: play 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 an sprite on the stage or above the scripts in Scratch

14 IN-CLASS EXERCISE create objects and call the appropriate methods to produce a picture like this

15 The Picture class now load the Picture project from the examples directory  the Picture class automates the drawing of the house picture  when the Draw method is called on a Picture object, the house picture is drawn EXERCISE: view the source code of Picture by double-clicking on its box EXERCISE: after the line sun.makeVisible(); add sun.slowMoveVertical(300); then save (Ctrl-S) and Compile 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, …