1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 18 What are programs for? Classes and Objects.

Slides:



Advertisements
Similar presentations
Relations & Functions Section 2-1.
Advertisements

CS104: Chapter 15 CS 104 Students and me. Big Question Q: You say creating a class is how to create a new type. Why would we even want to do this?! A:
Function in Notepad def drawSquare(myTurtle): myTurtle.forward(100) myTurtle.right(90) # side 1 myTurtle.forward(100) myTurtle.right(90) # side 2 myTurtle.forward(100)
Hypothesis:  I Believe that the younger generation uses cell phones and computers to their fullest capability then the older generation.
From datetime import * class StopWatch(object): def __init__(self): now = datetime.now() self.hr = now.hour self.min = now.minute self.sec = now.second.
Visual Communication Design Justin Quinlan. What is Visual Communication Design? The practice or profession of designing print or electronic forms of.
James Tam Classes and Objects You will learn how to define new types of variables.
Computer Science 111 Fundamentals of Programming I Introduction to Programmer-Defined Classes.
DAISY SLEEPS WITH HER RED BALL… …ON THE SOFA.
Guide to Programming with Python
I210 review (for final exam) Fall 2011, IUB. What’s in the Final Exam Multiple Choice (5) Short Answer (5) Program Completion (3) Note: A single-sided.
Guide to Programming with Python Chapter Eight (Part II) Object encapsulation, privacy, properties; Critter Caretaker game.
Centre for Computer Technology ICT115 Object Oriented Design and Programming Week 2 Intro to Classes Richard Salomon and Umesh Patel Centre for Information.
1 Survey of Computer Science CSCI 110, Spring 2011 Lecture 14 Recursion.
Co mputer Graphics Researched via: Student Name: Nathalie Gresseau Date:12/O7/1O.
CS101 Lecture 4 Computer Graphics. It ’ s just a bunch of pixels A computer screen is made up of many small colored squares called pixels The human eye.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 23 Game Graphics II.
Car make model year color turnOn() accelerate() decelerate() rollWindows()
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
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.
Class 2 Introduction to turtle graphics
Chapter 1. Objectives To provide examples of computer science in the real world To provide an overview of common problem- solving strategies To introduce.
English Logic and Writing
Xin Liu. * Use python 3.0 or later version * Major differences from earlier versions * Interactive mode * For quick experiments * “python3” to enter *
Classes 1 COMPSCI 105 S Principles of Computer Science.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Lecture 17 Parameters, Scope, Return values.

1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 4 Conditionals Turtles.
Lecture 24: Color Announcements & Review Lab 7 Due Thursday 2 D arrays - embedding graphs in an array Computer Science Artifacts Abstraction Representations.
WHAT IS COMPUTER SCIENCE? Phil Sands K-12 Outreach Coordinator for Computer Science.
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
Section 6.1 CS 106 Victor Norman IQ Unknown. The Big Q What do we get by being able to define a class?! Or Do we really need this?!
John A. Ferguson Senior High S.W. 56 Street Miami, FL
Object Oriented Programming In Python
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 25 Game Graphics--Text and Animation.
1 Computer Graphics and Games MONT 105S, Spring 2009 Lecture 2 Simple Python Programs Working with numbers and strings.
Sight Words Shoesmith Kindergarten Mrs. Cranley and Mrs. Stuttley.
Introduction to Chemistry 100 D. G. Marangoni. Course Information  Chemistry 100 NH F Block. LabsPSC 2045  Tuesday AM; Wednesday PM. Tutorial.
Section 9.3: The Dot Product Practice HW from Stewart Textbook (not to hand in) p. 655 # 3-8, 11, 13-15, 17,
PyGame - Unit 4 PyGame Unit – Object Oriented Programming OOP.
ISU AND YOUTHBUILD BRYAN HOSACK 12/07/2011 Introduction to Computing.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
Topic: Functions – Part 1
GCSE COMPUTER SCIENCE Computers 1.1 What is a Computer?
General Form for a Conditional
Technology in the past 50 years
Algorithm and Ambiguity
Computer Science 111 Fundamentals of Programming I
Functions CIS 40 – Introduction to Programming in Python
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Teaching KS3 Computing Session 4 Theory: Boolean logic AND/OR/NOT
Object-Oriented Programming
Software Usability and Design
INTRO TO COMPUTER SCIENCE
Guide to Programming with Python
Teach A-Level Computer Science: Object-Oriented Programming in Python
Teaching KS3 Computing Session 4 Theory: Boolean logic AND/OR/NOT
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Computer Science 111 Fundamentals of Programming I
Objects (again) Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction.
Solving Inequalities.
Title of you poster here
CSIS110 - Introduction to Computer Science
I am a student. We are students. You are a student. You are students. He is a student. She is a student. It is a student. They are students.
Graphical Analysis of Motion
CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation
CSIS110 - Introduction to Computer Science
Presentation transcript:

1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 18 What are programs for? Classes and Objects

2 What are Programs For? Everything computers do is a program: , Web surfing, Facebook applications, Word, Tetris, Games, etc. Programs are used in most electronic devices: Cars, TV's, Microwave ovens, cell phones

3 Why learn to program? Programming is a useful skill in many fields: Economics, All Sciences, Business, etc. Learning programming helps you to understand how computers function and what their limitations are. Computer Programming is about Problem solving. Learn to break problem into component parts Learn to think logically Learn to describe solutions to problems in a clear, step-by- step process.

4 Recall Classes and Objects A class describes a group of objects that have the same methods and set of properties. Objects have properties: Things that describe the objects Objects have methods: Things an object can do. Example: A car class Properties: color, make, model, year Methods: accelerate, brake, steer My car is an object that is a member of the car class. color: blue, make: Honda, model: Civic, year: 2003 My husband's car is another object that is a member of the car class. color: black, make: Toyota, model: Prius, year: 2007

5 The Turtle Class A turtle in python is an object from the Turtle class. Properties: x position, y position, direction, pen position, etc. Methods: forward(distance), backward(distance), left(angle), etc. When we write: yertle = Turtle( ) Python creates an object that is a member of the Turtle class. yertle is a reference to that object that we can use to access its methods using the dot notation: yertle.forward(150)

6 Writing a Class definition class Critter: color = "red"#color is a property mood = "happy"#mood is another property def talk(self):#talk is a method print "I am a critter!" def sing(self):#sing is another method print "Tra la la" #main program starts here crit = Critter( ) print crit.color crit.talk( ) crit.sing( )

7 Using self in a class method class Critter: color = "red" mood = "happy" def talk(self): print "I am a " + self.mood + " critter!" crit = Critter( ) crit.talk( ) We can use self to refer to a given object in a class method. Example:

8 The docstring The docstring is used to describe the objects in a class. Example: class Critter: """A virtual pet"""... crit = Critter( ): print crit.__doc__

9 The constructor function We can use a constructor function to initialize properties. Example: class Critter: """A virtual pet""" def __init__(self, clr, md): self.color = clr self.mood = md def talk(self): print "I am a " + self.mood + " critter!" crit = Critter("green", "sad") print crit.color crit.talk( )