1 CSC 221: Computer Programming I Fall 2004 Objects and classes: a first pass  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

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.
BlueJ: a very quick introduction. BlueJ BlueJ is an IDE (Interactive Development Environment). It includes –an editor, which you use to write your programs.
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
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.
13-Jul-15 BlueJ: A Very Quick Introduction. BlueJ BlueJ is an IDE (Integrated Development Environment). It includes an editor, which you use to write.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
Digital Image Processing Lecture3: Introduction to MATLAB.
Microsoft Visual Basic 2005 CHAPTER 1 Introduction to Visual Basic 2005 Programming.
Building and managing class pages on our new Web site School Wires Training.
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#
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.
BIM211 – Visual Programming Objects, Collections, and Events 1.
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.
CPS120: Introduction to Computer Science Compiling Your Programs Using Visual C++
Introduction to Java. 2 Textbook David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fourth edition, Pearson.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
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.
Chapter 1 Object Orientation: Objects and Classes.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Laboratory Exercise # 9 – Inserting Graphics to Documents Office Productivity Tools 1 Laboratory Exercise # 9 Inserting Graphics to Documents Objectives:
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.
Programmable Logic Training Course HDL Editor
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
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
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.
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 
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 CSC 221: Computer Programming I Fall 2005 Understanding class definitions  class structure  fields, constructors, methods  parameters  assignment.
Objects and Classes CITS1001 week 1.
CSC 222: Object-Oriented Programming
Introduction to Basic Interface of
CSC 222: Object-Oriented Programming
Java Programming with BlueJ
Java Applets.
Defining Classes and Methods
Presentation transcript:

1 CSC 221: Computer Programming I Fall 2004 Objects and classes: a first pass  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, Singer

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

3 Shape classes and objects a slightly 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:

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

5 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

6 Loading the shapes project BlueJ comes with a collection of example projects  click on the Project heading  select Open Project  browse to select C:  BlueJ  examples  shapes when a project loads, its classes are shown in a diagram  here, there are 4 classes  Canvas represents a painting area  Circle, Square, and Triangle represent shapes  the arrows show that the shapes depend upon the Canvas class

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

8 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

9 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

10 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

11 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 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

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

13 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

14 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

15 Textual example can define a Singer class to “sing” various children’s songs  instead of displaying shapes in a Canvas or returning a value, the methods of the Singer class display text in a window  methods include: oldMacDonaldSong() for “Old MacDonald Had a Farm” bottlesSong() for “100 Bottles of Dew on the Wall” busSong() for “The Wheels on the Bus”  each song utilizes a parameterized method to display a single verse oldMacDonaldVerse(animal, sound) bottlesSong(numBottles, drink) busSong(busPart, partAction)