1 CSC 221: Computer Programming I Spring 2008 Objects and classes: a broad view  software objects, classes, object-oriented design  BlueJ IDE, compilation.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.
Getting to know Greenfoot
SuperStar Basics Brian Bruderer. Sequence Editors Traditional sequence editors use a large grid to control when channels are turned on and off. This approach.
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.
Processing Processing is a simple programming environment that was created to make it easier to develop visually oriented applications with an emphasis.
REVIEW FOR SOME WELCOME TO THE COMPUTER!. WHY ARE COMPUTERS IMPORTANT?
REVIEW FOR SOME WELCOME TO THE COMPUTER!. WHY ARE COMPUTERS IMPORTANT?
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
1 CSC 221: Computer Programming I Fall 2006 See online syllabus (also accessible via Blackboard): Course goals:  To develop.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 2 Stewart Blakeway FML 213
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.
Java Tutorial – Building GUIs Java with Added Swing Daniel Bryant
Create slices and hotspots Create links in Web pages Create rollovers from slices Create basic animation Add tweening symbol instances to create animation.
Introduction to Alice Basics : What is Alice? Object Oriented Definitions What Does it Look Like? Where Can I Use it?
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.
Welcome to the Computer!
Building and managing class pages on our new Web site School Wires Training.
1 CSC 221: Computer Programming I Fall 2004 Objects and classes: a first pass  software objects, classes, object-oriented design  BlueJ IDE, compilation.
A First Program Using C#
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
Inserting Pictures and Symbols in Word documents There are many ways to insert pictures – these are the most common methods Copy and Paste Copy and paste.
Programming Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
PowerPoint Basics (for Macs) 1. Before you start your project, you need: Completed project storyboard. Files with images, sound, or video already saved.
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.
1.  A method describes the internal mechanisms that actually perform its tasks  A class is used to house (among other things) a method ◦ A class that.
1 CSC 221: Computer Programming I Spring 2010 Objects and classes: a broad view  Scratch programming review  object-oriented design, software objects.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
CPS120: Introduction to Computer Science Compiling Your Programs Using Visual C++
OBJECTS AND CLASSES CITS1001. Concepts for this lecture class; object; instance method; parameter; signature data type multiple instances; state method.
1 COS 260 DAY 2 Tony Gauvin. 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Greenfoot Game Programming Club.
Flash CS 5 Interface BY NSCHEWCZYK | ©2012. MENU BAR A bar at the top of the window. It lists menu options including: File, Edit, View, Insert, Modify,
1 CSC 222: Object-Oriented Programming Spring 2013 Objects and classes: a first pass  221 review  software objects, classes, object-oriented design 
Chapter 4 Introduction to Classes, Objects, Methods and strings
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
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.
Using This PowerPoint This PowerPoint presentation assumes your Computer Science teacher has provided you with the InstallingJava folder, which contains.
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
The desktop (overview) Working with desktop icons The desktop is the main screen area that you see after you turn on your computer and log on to Windows.
Compiling and running Java programs with BlueJ. Successfully compiled files program files in BlueJ You can tell from the shade of a program icon in BlueJ.
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 
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
What’s on Your Desktop?. Programs on your computer Some programs are standard on most computers for example: Microsoft Word Internet Explorer Microsoft.
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 I 3.01 Apply Controls Associated With Visual Studio Form.
Alice in Action with Java Chapter 1 Getting Started with Alice.
Today We Will Review: Operating Systems (Windows) (week 3 & 4) Starting up MS Windows Desktop and its contents Functions of the desktop components Brain.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
CSC 222: Object-Oriented Programming
CSC 222: Object-Oriented Programming
Java Programming with BlueJ
Alice in Action with Java
Java Applets.
Inserting Pictures and Symbols in Word documents
Defining Classes and Methods
Presentation transcript:

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

2 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 Alice: class: lighthouse, frog, cow, …(a variety could be viewed at bottom) object: frog1, frog2, …(created by dragging the class icon) properties/fields: size, color, orientation, …(could view/alter at bottom left) behaviors/methods: turn, move, think, …(could execute by dragging to right)

3 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

4 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:

5 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, …

6 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

7 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 scene)  Circle, Square, and Triangle represent shapes  the arrows show that the shapes depend upon the Canvas class corresponds to the class icons across the screen in Alice

8 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 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, …)

9 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 dragging the class icon into the scene in Alice

10 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 method icon to the script and clicking Play in Alice

11 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 methods in Alice required parameters (e.g., move speed & distance)

12 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 object at the lower-left in Alice

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

14 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 scripted scene in Alice

15 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, …