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.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Computer Science 112 Fundamentals of Programming II User Interfaces
Python Objects and Classes
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
OBJECT ORIENTED PROGRAMMING (OOP) IN PYTHON David Moodie.
CS 211 Inheritance AAA.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Guide to Programming with Python
REFERENCES: CHAPTER 8 Object-Oriented Programming (OOP) in Python.
Guide to Programming with Python
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Guide to Programming with Python Chapter Eight (Part II) Object encapsulation, privacy, properties; Critter Caretaker game.
Chapter 12 Inheritance and Exceptions Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas,
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Chapter 8: Writing Graphical User Interfaces
Peter Andreae Python for Level 3 CS4HS see website: ecs.vuw.ac.nz/Main/PythonForSchools.
Guide to Programming with Python Chapter Ten GUI Development: The Mad Lib Program.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 23 Game Graphics II.
Guide to Programming with Python
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Computer Science 111 Fundamentals of Programming I Model/View/Controller and Data model design.
1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman.
PYTHON GUI PROGRAMMING
Computer Science 112 Fundamentals of Programming II Command Buttons and Responding to Events.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 20 Graphical User Interface (GUI)
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
Guide to Programming with Python Week 11 Chapter Nine Inheritance Working with multiple objects.
How the Session Works Outline Practical on arrival Talk 1 Reflect on practical Clarify concepts Practical exercises at your own pace Talk 2: Further concepts.
Chapter Object Oriented Programming (OOP) CSC1310 Fall 2009.
Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
Understanding Desktop Applications Lesson 5. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Windows Forms Applications Understand.
Object Oriented Programming In Python
Guide to Programming with Python
Object-Oriented Programming: Inheritance and Polymorphism.
Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 22 Game Graphics.
PyGame - Unit 4 PyGame Unit – Object Oriented Programming OOP.
COMPSA Exam Prep Session by Paul Allison On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.
Object-Oriented Programming (OOP) in Python References: Chapter 8.
CMSC201 Computer Science I for Majors Lecture 25 – Classes
Object-Orientated Programming
Guide to Programming with Python
Topics Graphical User Interfaces Using the tkinter Module
Graphical User Interfaces (GUIs)
Chapter 1: An Introduction to Visual Basic 2015
Computer Science 111 Fundamentals of Programming I
Software Development Java Classes and Methods
An Introduction to Inheritance
Lecture VI Objects The OOP Concept Defining Classes Methods
Graphical User Interfaces -- Introduction
Fundamentals of Python: From First Programs Through Data Structures
Event Driven Programming
Chapter 15 Event-Driven Programming and Animations
Inheritance Chapter 7 Chapter 7.
The super Reference Constructors cannot be used in child classes, even though they have public visibility Yet we often want to use the parent's constructor.
Guide to Programming with Python
I210 review.
Fundamentals of Programming I Windows, Labels, and Command Buttons
Computer Science 111 Fundamentals of Programming I User Interfaces
Object-Oriented Programming: Inheritance and Polymorphism
Guide to Programming with Python Book is by Michael Dawson
ICT Gaming Lesson 3.
Presentation transcript:

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 A4 cheat-sheet is allowed; write your name and ID on the cheat-sheet; and turn in your cheat-sheet together with the final exam.

Basics Variables Data types –list –conversion Branching structures Loops (while & for loops) Functions –Function header –Return values –Parameters and arguments 3

Understanding OOP OOP allows representation of real-life objects as software objects (e.g., a dictionary as an object) Object: A single software unit that combines attributes and methods Attribute: A "characteristic" of an object; like a variable associated with a kind of object Method: A "behavior" of an object; like a function associated with a kind of object Class: Code that defines the attributes and methods of a kind of object (A class is a collection of variables and functions working with these variables) 4

Creating Classes for Objects class Puppy(object): def __init__(self, name, color): self.name = name self.color = color def bark(self): print "I am", self.color, self.name puppy1 = Puppy("Max", "brown") puppy1.bark() puppy2 = Puppy("Ruby", "black") puppy2.bark() Class: Code that defines the attributes and methods of a kind of object Instantiate: To create an object; A single object is called an Instance 5

Special Methods def __init__(self): print "A new critter has been born!” #Constructor, __init__() #Automatically called by new Puppy object def __str__(self): rep = "Critter object\n" rep += "name: " + self.name + "\n" return rep # __str__() # return a string 6

Private vs Public Attributes and Methods Public: Can be directly accessed by client code Private: Cannot be directly accessed (easily) by client code By default, all attributes and methods are public But, can define an attribute or method as private class Critter(object): def __init__(self, name, mood): self.name = name # public self.__mood = mood # private 7

Understanding Inheritance Inheritance: An element of OOP that allows a new class to be based on an existing one where the new automatically gets (or inherits) all of the methods and attributes of the existing class The children classes get all the capabilities (methods) and properties (attributes) the parent class has; the children classes are also called derived classes Get the code for free! (code-reuse) – inheritance allows a new class to re-use code which already existed in another class (the parent class) 8

Derived Classes are New Classes To create specializations of existing classes or objects by adding new attributes and methods! –often called subtyping when applied to classes. In specialization, the new class or object has data or behavior aspects that are not part of the inherited class. Overriding (e.g., over-ridding of the + operator, so + has different meaning, addition of two numbers, concatenation of two strings, etc) – the same method that does something different Guide to Programming with Python 9

Altering the Behavior of Inherited Methods: Overriding Override: To redefine how inherited method of base class works in derived class Two choices when overriding –Completely new functionality –Incorporate functionality of overridden method, add more How to invoke base class’ methods? 10

11 class Animal(object): def __init__(self, name): # Constructor self.name = name def get_name(self): return self.name class Cat(Animal): def talk(self): return 'Meow!' class Dog(Animal): def talk(self): return 'Woof! Woof!' animals = [Cat('Missy'), Cat('Mr. Bojangles'), Dog('Lassie')] for animal in animals: print animal.talk() + ' I am ' + animal.get_name() Inheritance Example: Animal Class Base class: A class upon which another is based; it is inherited from by a derived class Derived (child) class: A class that is based upon another class; it inherits from a base class

Understanding Event-Driven Programming Event-driven program: A program that responds to actions regardless of the order in which they occur (vs structured programming) Event: Something that happens involving a program's objects (mouse moves over; click of a button, etc) Event handler: Code that runs when a specific event occurs Bind: To associate an event with an event handler Event loop: A loop that checks for events and calls appropriate event handlers when they occur GUI programs traditionally event-driven: the users control the flow of the program 12

Buttons on Strike from Tkinter import * root = Tk() # a root window, upon which other GUI elements can be added root.title("Simple GUI Demo") #add title root.geometry("400x200") #change the size of the window app = Frame(root) # create a frame, upon which other Widgets can be added app.grid() #need to invoke grid() method button = Button(app, text = "I am button #1”) button.configure(text = "I am button #2”) button['text'] = "I am button #3” button["command"] = update_count button.grid() root.mainloop() #must start up the window's event loop!!! 13 (I) (II) (III) (IV)

Writing a Game Using Pygame & Livewires #(1) Import pygame or livewires from livewires import games #(2) Create a graphical window games.init(screen_width = 640, screen_height = 480, fps = 50) #(3) Start up window’s main loop games.screen.mainloop() 14

Understanding the Graphics Coordinate System Graphics screen made up of rows and columns of pixels Specify point on screen with coordinates: x and y ; Upper-leftmost pixel is (0,0) Can place graphics objects on screen using coordinate system 15 screen.width screen.height

Control a Sprite Sprite: A graphics object with an image class Pizza(games.Sprite): """ A bouncing pizza. """ def update(self): if games.keyboard.is_pressed(games.K_UP): self.x -= 1 if self.right > games.screen.width or self.left < 0: self.dx = -self.dx if self.bottom > games.screen.height or self.top < 0: self.dy = -self.dy 16

Sample Question 1 In Pygame, what is a sprite? What is a sprite collision? 17

Sample Question 2 Complete the following GUI code that creates a button… from ____________ import * class Application(Frame): def __init__(self, master): Frame.__init__(self, master) self.grid() ___________________________ self.create_widget() def create_widget(self): self.lbl = Label(self, text="Click to increment!") ________________________ self.bttn = Button(self)...